問題一覧 > 通常問題

No.839 Keep Distance and Nobody Explodes

レベル : / AI推定難易度 : 1950 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 69
作問者 : やむなく / テスター : heno239
お気に入りにしたユーザー ProblemId : 2617 / 自分の提出
問題文最終更新日: 2019-06-15 00:17:36
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 215 (順位表) の他の問題:

Flavor Text

Thanks to communication with your trusted companion, you succeeded in defusing the bomb!
The only job left is to transport the dismantled parts.
Having escaped danger, you were preparing with complete relief, when a serious problem came to light!
If parts with adjacent numbers are carelessly brought close together, the parts will reboot!
You had planned to put the parts back into the bomb case to carry them, but unless you arrange their positions carefully, you will once again face the danger of an explosion...

Problem Statement

Let $N$ be a positive

even number

, and consider an $N \times N$ grid.
Write $1$ of the integers between $1$ and $N^2$, inclusive, in each cell of the grid so that no $2$ cells contain the same number.
Let $(i,j)$ denote the cell in the $i$-th row from the top and the $j$-th column from the left, and let $(X_k,Y_k)$ be the cell in which the integer $k\ (1 \le k \le N^2)$ is written.
Your goal is to maximize the minimum distance between $2$ cells whose written numbers differ by $1$, that is, to maximize ${\rm min}_{2 \le k \le N^2}\{(X_k-X_{k-1})^2+(Y_k-Y_{k-1})^2\}$.
Find $1$ way of writing the numbers that achieves this.

Input

$N$

  • $2 \le N \le 300$
  • $N$ is a positive

    even number

    .

Output

Output $1$ way of writing the numbers that satisfies the problem statement.

Specifically, output $N$ lines as follows.
Let $A_{i,j}$ denote the integer written in cell $(i,j)$.
On line $i$ $(1 \le i \le N)$, output the $N$ integers $A_{i,j}$ $(1 \le j \le N)$, separated by spaces.

$
        \begin{matrix}
        A_{1,1} & A_{1,2} &  \cdots &  A_{1,N} \\
        A_{2,1} & A_{2,2} &  \cdots &  A_{2,N} \\
        \vdots  & \vdots  &         &  \vdots  \\
        A_{N,1} & A_{2,N} &  \cdots &  A_{N,N} 
        \end{matrix}
        $

Sample

Sample 1
Input
2
Output
1 2
3 4

In this output, we have
$(X_2-X_1)^2+(Y_2-Y_1)^2=1+0=1$
$(X_3-X_2)^2+(Y_3-Y_2)^2=1+1=2$
$(X_4-X_3)^2+(Y_4-Y_3)^2=1+0=1$
.
When $N=2$, the value of ${\rm min}_{2 \le k \le N^2}\{(X_k-X_{k-1})^2+(Y_k-Y_{k-1})^2\}$ is always $1$, so any way of writing the numbers that you output will be judged correct.

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