atcoder#ABC177F. [ABC177F] I hate Shortest Path Problem
[ABC177F] I hate Shortest Path Problem
Score : points
Problem Statement
There is a grid of squares with horizontal rows and vertical columns.
You will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer from through , you cannot move down from the -th, -th, , -th squares from the left in the -th row from the top.
For each integer from through , find the minimum number of moves needed to reach one of the squares in the -th row from the top. (The starting square can be chosen individually for each case.) If, starting from any square in the top row, none of the squares in the -th row can be reached, print -1
instead.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the answer for the case .
4 4
2 4
1 1
2 3
2 4
1
3
6
-1
Let denote the square at the -th row from the top and -th column from the left.
For , we need one move such as → .
For , we need three moves such as → → → .
For , we need six moves such as → → → → → → .
For , it is impossible to reach any square in the fifth row from the top.