6691.Mex Grid Construction

Time Limit: 1s Memory Limit: 512MB

Your task is to construct an $n \times n$ grid where each square has the smallest nonnegative integer that does not appear to the left on the same row or above on the same column.

Input Format(From the terminal/stdin)

The only line has an integer $n$ .

  • $1 \le n \le 100$

Output Format(To the terminal/stdout)

Print the grid according to the example.

Sample Input

Copy
5
 \n

Sample Output

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

Submit

请先 登录

© 2025 FAQs