6692.Knight Moves Grid

Time Limit: 1s Memory Limit: 512MB

There is a knight on an $n \times n$ chessboard. For each square, print the minimum number of moves the knight needs to do to reach the top-left corner.

Input Format(From the terminal/stdin)

The only line has an integer $n$ .

  • $4 \le n \le 1000$

Output Format(To the terminal/stdout)

Print the number of moves for each square.

Sample Input

Copy
8
 \n

Sample Output

Copy
0 3 2 3 2 3 4 5 
3 4 1 2 3 4 3 4 
2 1 4 3 2 3 4 5 
3 2 3 2 3 4 3 4 
2 3 2 3 4 3 4 5 
3 4 3 4 3 4 5 4 
4 3 4 3 4 5 4 5 
5 4 5 4 5 4 5 6
 · · · · · · · \n
 · · · · · · · \n
 · · · · · · · \n
 · · · · · · · \n
 · · · · · · · \n
 · · · · · · · \n
 · · · · · · · \n
 · · · · · · · \n
Source: CSES, Introductory Problems, 3217

Submit

请先 登录

© 2025 FAQs