問題一覧 > 通常問題

No.1587 012 Matrix

レベル : / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 160
作問者 : e869120 / テスター : 沙耶花
お気に入りにしたユーザー ProblemId : 6691 / 自分の提出
問題文最終更新日: 2021-07-08 23:11:59
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 303 (順位表) の他の問題:

Problem Statement

There is a grid with $N$ rows and $N$ columns (here, $N$ is even). yuki wants to write $0$, $1$, or $2$ in each cell. In doing so, the following condition must be satisfied.

  • Let $A_i$ be the sum of the integers written in the $i$-th row from the top $(1 \leq i \leq N)$.
  • Let $B_j$ be the sum of the integers written in the $j$-th column from the left $(1 \leq j \leq N)$.
  • Then, the $2N$ integers $A_1, A_2, \cdots, A_N, B_1, B_2, \cdots, B_N$ are pairwise distinct.
Determine whether it is possible to write $0, 1, 2$ in the cells so that this condition is satisfied, and if it is possible, output one such way of writing them.

Input

$N$

Output

If it is impossible to write $0, 1, 2$ in the cells so that the condition is satisfied, output No.

If it is possible, output $1$ way of writing them that satisfies the condition, in the following format.

$s_{1, 1}$$s_{1, 2}$$\cdots$$s_{1, N}$
$s_{2, 1}$$s_{2, 2}$$\cdots$$s_{2, N}$
 $\vdots$
$s_{N, 1}$$s_{N, 2}$$\cdots$$s_{N, N}$
Here, $s_{i, j}$ is the integer written in the cell at the $i$-th row from the top and the $j$-th column from the left.
If there are multiple solutions, any of them will be accepted.

Constraints

  • $2 \leq N \leq 500$
  • $N$ is even

Sample

Sample 1
Input
2
Output
01
22

The sum $A_1$ of the integers written in the $1$-st row from the top is $0 + 1 = 1$.
The sum $A_2$ of the integers written in the $2$-nd row from the top is $2 + 2 = 4$.
The sum $B_1$ of the integers written in the $1$-st column from the left is $0 + 2 = 2$.
The sum $B_2$ of the integers written in the $2$-nd column from the left is $1 + 2 = 3$.
They are all distinct, so this output is correct.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。