Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Introductory Problems

Mex Grid Construction

#3419
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

Your task is to construct an n×nn \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

The only line has an integer nn.

Output

Print the grid according to the example.

Constraints
  • 1≤n≤1001 \le n \le 100
Sample Test Cases (1)
Example 1ID: sample-1
Input
5
Expected Output
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
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
5
Expected Output
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