No.839 Keep Distance and Nobody Explodes
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もしくは右上の雲マークをクリックしてアカウントを作成してください。
やむなく
heno239