Copying Coins
Time limit1sMemory limit1024 MB
Given an N by N grid with one coin at (x, y), find the minimum number of directional machine runs needed to fill every cell with coins.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation
- Solved
- No attempts yet
Problem
Raymu is sad because he has no money, and one day he finds a machine. The machine is a square with side length , made of cells. Cells are addressed by coordinates: the bottom-left cell is and the top-right cell is . At the start, only the cell has a coin, and all other cells are empty. Here is the cell steps right and steps up from .
Raymu can run the machine once in one of four directions: up, down, left, or right. Every coin in the machine moves in the direction the machine runs, and new coins appear along the path each coin travels. Raymu wants to fill every cell of the machine with coins, and he wants to minimize the number of runs. Given the side length and the starting position of the coin, find the minimum number of runs needed to fill every cell.
Input
The first line contains the side length of the machine. ()
The second line contains two integers and separated by a space, the starting position of the coin. ()
Output
Print the minimum number of machine runs.