No.1169 Row and Column and Diagonal
タグ : / 解いたユーザー数 360
作問者 :
opt
/ テスター :
Enjapma_kyopro
Problem Statement
You are given a positive odd integer $N$. Find one tuple of $N^2$ integers $(a_{i,j})_{1 \leq i,j \leq N}$ that satisfies all of the following conditions:
- For each integer $i = 1,\dots,N$, $(a_{i,1},a_{i,2},\dots,a_{i,N})$ is a permutation of $(1,2, \dots, N)$.
- For each integer $i = 1,\dots,N$, $(a_{1,i},a_{2,i},\dots,a_{N,i})$ is a permutation of $(1,2, \dots, N)$.
- For each integer $i = 1,\dots,N$, $a_{i,i} = i$.
It can be shown that such a tuple of integers always exists.
Input
The input is given in the following format:
$N$
- $N$ is odd
- $1 \leq N < 500$
Output
Output a tuple of integers $(a_{i,j})_{1 \leq i,j \leq N}$ satisfying the conditions, in the following format:
$a_{1,1} \quad a_{1,2} \quad \cdots \quad a_{1,N}$
$a_{2,1} \quad a_{2,2} \quad \cdots \quad a_{2,N}$
$\ \ \vdots$
$a_{N,1} \quad a_{N,2} \quad \cdots \quad a_{N,N}$
Print a newline at the end.
If there are multiple tuples of integers satisfying the conditions, you may output any of them.
Sample
Sample 1
Input
5
Output
1 5 2 3 4 4 2 1 5 3 5 4 3 1 2 2 3 5 4 1 3 1 4 2 5
This output can be verified to satisfy the $1$ st condition as follows:
- $(a_{1,1}, a_{1,2}, a_{1,3}, a_{1,4}, a_{1,5}) = (1,5,2,3,4)$ is a permutation of $(1,2,3,4,5)$.
- $(a_{2,1}, a_{2,2}, a_{2,3}, a_{2,4}, a_{2,5}) = (4,2,1,5,3)$ is a permutation of $(1,2,3,4,5)$.
- $\ \vdots$
- $(a_{5,1}, a_{5,2}, a_{5,3}, a_{5,4}, a_{5,5}) = (3,1,4,2,5)$ is a permutation of $(1,2,3,4,5)$.
Similarly, it also satisfies the $2$ nd condition. It also satisfies the $3$ rd condition.
Any tuple of integers satisfying the conditions will be accepted.
Sample 2
Input
1
Output
1
All $3$ conditions are satisfied.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。