問題一覧 > 通常問題

No.3727 Garden Master

レベル : / AI推定難易度 : 1925 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 64
作問者 : 👑 kencho / テスター : uruzunyaa 👑 p-adic
お気に入りにしたユーザー ProblemId : 13575 / 自分の提出
問題文最終更新日: 2026-11-02 04:26:57
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
グリッド構築24題 (順位表) の他の問題:

Problem Statement

There is a flower bed in the form of an $N \times N$ grid.

You are a gardener and have decided to plant red roses and blue roses in each cell.

To create an artistic flower bed, find one example of a way of planting that satisfies all of the following conditions.

  • The number of red roses and the number of blue roses planted in each cell are each at least $1$ and at most $N$.
  • The pairs of the numbers of red roses and blue roses planted in the cells are all distinct.
    • That is, for any $2$ different cells, the pairs (number of red roses, number of blue roses) must not coincide.
  • For any $4$ cells arranged in a $2 \times 2$ square, the total number of red roses and the total number of blue roses are equal.
    • Here, $4$ cells arranged in a $2 \times 2$ square means the $4$ cells forming the intersection of $2$ consecutive rows and $2$ consecutive columns; there are $(N-1)^2$ such squares in total.

If no such way of planting exists, output -1.

Constraints

  • All inputs are integers.
  • $2 \leq N \leq 500$

Input

The input is given from standard input in the following format.

$N$

Output

If a way of planting satisfying the conditions exists, output one example in the following format, where $R_{i, j}$ is the number of red roses and $B_{i, j}$ is the number of blue roses planted in the cell in the $i$-th row from the top and the $j$-th column from the left of the grid.

If no way of planting satisfying the conditions exists, output -1.

$R_{1, 1}\ R_{1, 2}\ \ldots\ R_{1, N}$
$R_{2, 1}\ R_{2, 2}\ \ldots\ R_{2, N}$
$\vdots$
$R_{N, 1}\ R_{N, 2}\ \ldots\ R_{N, N}$
$B_{1, 1}\ B_{1, 2}\ \ldots\ B_{1, N}$
$B_{2, 1}\ B_{2, 2}\ \ldots\ B_{2, N}$
$\vdots$
$B_{N, 1}\ B_{N, 2}\ \ldots\ B_{N, N}$

Print a newline at the end.

Visualizer

A web-based visualizer for the output is available here.

During the contest, sharing visualization results and mentioning solutions or insights is prohibited. Please be careful.

In principle, we do not accept questions about the specifications of the visualizer. Please use it only as an auxiliary tool.

Sample

Sample 1
Input
3
Output
3 2 2
1 3 1
2 3 1
1 3 2
3 2 1
1 3 2

The number of roses of each color planted in each cell is as shown in the figure below.

For example, in the $4$ cells arranged in the top-left $2 \times 2$ square, a total of $9$ red roses and a total of $9$ blue roses are planted.

For the other $4$ cells arranged in a $2 \times 2$ square as well, the numbers of red roses and blue roses are equal.

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