#abc272d. D - Root M Leaper
D - Root M Leaper
Score : points
问题描述
存在一个 的网格。我们用 表示从上到下第 行、从左到右第 列的格子。
初始时,棋子位于 。你可以任意次数地重复以下操作:
- 让 表示棋子当前所在的格子,将棋子移动到距离 等于 的格子上。
这里,我们定义格子 和格子 之间的距离为 。
对于所有格子 ,确定棋子是否能够到达该格子。如果可以,找出完成这一操作所需的最少步骤数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a grid with squares. We denote by the square at the -th row from the top and -th column from the left.
Initially, a piece is placed on . You may repeat the following operation any number of times:
- Let be the square the piece is currently on. Move the piece to the square whose distance from is exactly .
Here, we define the distance between square and square as .
For all squares , determine if the piece can reach . If it can, find the minimum number of operations required to do so.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain integers. If the piece can reach , the -th integer in the -th line should be the minimum number of operations required to do so; otherwise, it should be .
Sample Input 1
3 1
Sample Output 1
0 1 2
1 2 3
2 3 4
You can move the piece to four adjacent squares.
For example, we can move the piece to with two operations as follows.
- The piece is now on . The distance between and is exactly , so move the piece to .
- The piece is now on . The distance between and is exactly , so move the piece to .
Sample Input 2
10 5
Sample Output 2
0 3 2 3 2 3 4 5 4 5
3 4 1 2 3 4 3 4 5 6
2 1 4 3 2 3 4 5 4 5
3 2 3 2 3 4 3 4 5 6
2 3 2 3 4 3 4 5 4 5
3 4 3 4 3 4 5 4 5 6
4 3 4 3 4 5 4 5 6 5
5 4 5 4 5 4 5 6 5 6
4 5 4 5 4 5 6 5 6 7
5 6 5 6 5 6 5 6 7 6
update @ 2024/3/10 11:27:48