Overgrown-Puzzled
Time limit3sMemory limit1024 MB
Find the starting cell on a ring of N cells with unknown icing types, using at most M moves and only a same-cell check after each move.
- Level
Hard9 of 10
- Topics
- Simulation, Implementation, Math
- Solved
- No attempts yet
Problem
One ordinary day, Seowoo met a strange rabbit named Nicky on the way to school. Nicky kept muttering that it was busy while holding a pocket watch.
Seowoo was drawn in by Nicky and followed it. When Nicky ran into a rabbit hole at a dead end, Seowoo hesitated for a moment and then jumped in after it.
Some time later, Seowoo woke up to find that they had crash-landed on top of a giant donut in a fantastic toy land. The surface had exactly the same shape as the donut with milk, strawberry, and chocolate icing that Seowoo had been carrying to school. The giant donut is a ring of cells, and each cell is numbered with an integer from 0 to . If you move clockwise from cell 0 one cell at a time for moves, cells , , ..., , and appear in that order.
Nicky explained the rules of the donut exploration and hurried Seowoo along.
- Seowoo lands at an arbitrary position on the giant donut at the start. Nicky starts in the same cell as Seowoo.
- Seowoo can move one cell clockwise or counterclockwise. Seowoo can move at most times.
- Right after Seowoo moves, Nicky moves. Nicky compares the icing type of the cell Seowoo stood on before moving with the icing type of the cell Nicky is currently on. Nicky moves one cell in the same direction Seowoo moved only if the icing types differ. If they are the same, Nicky does not move.
- After both have moved, Seowoo can check whether Nicky is in the same cell. No other information, such as the distance between them, is available.
- Seowoo can say the number of the cell where they first landed at any time. If Seowoo is correct, Nicky will take Seowoo to a new world.
Seowoo tried moving around to work out where they were, but having jumped into the rabbit hole unprepared, had no way to make progress and failed the first puzzle.
Charmed by the new world beyond Nicky's rabbit hole, Seowoo decided to make a new donut and jump in again. Nicky will state the movement limit differently depending on the size of the donut Seowoo brings, so Seowoo must make a donut with exactly cells. Write a program that helps Seowoo solve Nicky's first puzzle.