問題一覧 > 通常問題

No.1169 Row and Column and Diagonal

レベル : / AI推定難易度 : 1125 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 360
作問者 : opt / テスター : Enjapma_kyopro
お気に入りにしたユーザー ProblemId : 4809 / 自分の提出
問題文最終更新日: 2020-08-21 14:03:13
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 261 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。