The other day I came up with a problem and I'd appreciate some honest feedback as to whether or not it's a good (enjoyable/interesting) problem. I'd also appreciate it if you could gauge its difficulty by voting below. And I'd appreciate any feedback.
Problem Statement:
You are given an integer $$$n$$$ where $$$1 \le n \le 2000$$$. Consider a square grid with $$$n$$$ rows and $$$n$$$ columns. You are tasked with arranging the first $$$n^2$$$ whole numbers (that is, the integers $$$0, \,1, \,2 \,...\, n^2 - 3,\,n^2 - 2,\,n^2 - 1$$$) inside the grid, with exactly one number on each cell of the grid.
A frog starts in the bottom-left cell of the grid. The number of the cell the frog is currently on will tell the frog a magnitude and a direction to jump. Specifically, say the frog is at a cell that contains the number $$$a$$$.
The frog will then jump a magnitude of $$$\lfloor \frac{a}{4} \rfloor + 1$$$ units in the direction of $$$a \mod 4$$$.
As for the direction, let a value of $$$0$$$ represent a jump to the right, a value of $$$1$$$ represent a jump upwards, a value of $$$2$$$ represent a jump to the left, and a value of $$$3$$$ represent a jump downwards.
For example, if the frog is currently on a cell with the number $$$9$$$, then the frog will jump $$$\lfloor \frac{9}{4} \rfloor + 1 = 3$$$ units and in the upwards direction, since $$$9 \mod 4 = 1$$$, and $$$1$$$ represents a jump upwards.
Starting at the bottom-left cell, the frog will make a series of jumps around the grid based on the number in his current cell. However, if the frog sees that his next jump will lead him off of the grid, then he will not make that jump and stop in his current cell permamently.
Your task is to find and output the maximum number of jumps the frog can perform, given that he starts off in the bottom-left corner. The frog does not want to jump forever; he wants to perform the maximum finite number of jumps.
You also should output a grid where, if the frog were to start in the bottom-left cell of the grid, he could make that maximum number of jumps, without jumping forever. If multiple grids allow for maximum jumps, you can output any.
Input:
a single integer $$$n$$$ where $$$1 \le n \le 2000$$$.
Output:
a single integer representing the maximum number of jumps the frog can perform without jumping forever followed by any $$$n \times n$$$ grid that allows the frog to perform exactly that many jumps.
This problem is:
This problem's difficulty most closely aligns with:











Keep it up, genuinely good problem.
Would fit Div.1 A /Div.2 C the most imho.
This problem is really good. The bonus is almost of the same difficulty, just a bit more cautious about the choices.
So the total magnitude of all the valid jumps is 4(1+2+⋯+(n−1)) = 2n(n−1). We must drop at least one of them, otherwise every jump is cancelled by its opposite and the frog gets stuck in cycles. So the distance is at most 2n(n−1)−1, which is achieved only when the dropped jump has magnitude 1.
But not just any jump of magnitude 1. If all others are used, they will cancel in opposite pairs, so the frog finishes exactly one step opposite to the dropped jump from where it started. Starting in the bottom-left corner, the dropped jump must be the one going left or the one going down. Dropping the downward one means the path must end exactly one cell above the start, which is the extra constraint the max-jumps construction never had to satisfy.
Instead of one long zigzag, do a small trip from the leftmost column to each column, once at a time. Start with right 1, up n−1, left 1. Now the frog is at the top of the left column. Then for each column j from 2 to n−1: jump right j, fall all the way down to the bottom row, go back up but stop one row below where you fell from, then jump left j to return to the left column. Every trip brings the frog back one row lower, so it uses the left column at heights n−1, n−2, …, 1 and finally ends one cell above the start. All the jumps cover there magnitude except one down. That is 4n−5 jumps and 2n(n−1)−1 units. Put a number with magnitude at least n in the last cell, and put the rest of the numbers anywhere.
nice sol, I couldn't quite come up with a way to do that one, but I was pretty sure it was possible (I tried extending the zig-zag that my original sol had, but you can't take up an entire row on the bottom, since then you can't do the two vertical $$$n - 1$$$ jumps). yours is kind of like an inductive sol, since once you expend all jumps of length $$$n - 1$$$, $$$n - 2$$$, $$$n - 3$$$, you are left with solving an $$$n - 1 \times n - 1$$$, $$$n - 2 \times n - 2$$$, $$$n - 3 \times n - 3$$$ grid, respectively.
Nice problem. I have a somewhat diabolical solution. This took me way too long lol
Basically I have the same observation as yours, if the grid is $$$n$$$ by $$$n$$$, then we should be maxing out our usage of all jumps $$$1, 2, ..., n-1$$$, except we can't use them all because that would be in a cycle so the best we can do is all but one.
Recursive spec: $$$solve(n)$$$ returns a valid solution, such that you start from the bottom left corner, end at one square left from the bottom right corner, and use all jumps of $$$1, 2, ..., n-1$$$, except $$$n-2$$$ to the left.
Base case $$$n = 3$$$: right 2, up 2, left 2, down 1, right 1, up 1, down 2.
Base case $$$n = 4$$$: right 3, up 3, left 3, down 2, right 2, up 2, down 1, left 1, up 1, down 3, right 1.
Inductive case: $$$n = n; n \ge 5$$$: Assume that $$$(1, 1)$$$ is the bottom left corner and we're using XY coordinate axes. Perform:
You can verify that we used every jump except $$$n-2$$$ to the left.
In order to end the cycle, we just need to place an invalid jump (one that is $$$\ge n$$$) in the last spot. This is trivial for $$$n \ge 3$$$, but for $$$n=2$$$ it's not possible and the best we can do there is 1 jump, and then place an invalid one.