Universal Cup Judging System

Universal Cup

시간 제한: 3.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

正の偶数 $n$ が与えられます。行と列がともに $1$ から $n$ まで番号付けされた $n\times n$ のグリッドを考えます。行 $r$、列 $c$ のマスを $(r,c)$ と表します。

グリッドのすべての $n^2$ 個のマスを、各マスがちょうど一度現れる列 $p_1,p_2,\ldots,p_{n^2}$ に並べてください。ただし、$p_{n^2+1}=p_1$ と定めたとき、$1$ から $n^2$ までのすべての $i$ について、マス $p_i$ と $p_{i+1}$ は同じ行または同じ列にあり、次の条件を満たす必要があります。

$$ |r_i-r_{i+1}|+|c_i-c_{i+1}|=((i-1)\bmod 4)+1, $$

ここで、$p_i=(r_i,c_i)$、$p_{i+1}=(r_{i+1},c_{i+1})$ です。

言い換えると、この列はすべてのマスを一度ずつ訪れる長さ $n^2$ の閉じた巡回路でなければなりません。各移動は水平方向または垂直方向であり、移動距離は $1,2,3,4,1,2,3,4,\ldots$ のように周期的に繰り返されます。これには $p_{n^2}$ から $p_1$ に戻る最後の移動も含まれます。

そのような列が存在する場合は、そのうちのいずれかを出力してください。

入力

最初の行には、偶数 $n$ ($4\le n\le 200$) が一つ含まれます。

出力

条件を満たす列が存在しない場合は、NO を含む一行を出力してください。

そうでない場合は、最初の行に YES を出力し、その後に、それぞれ $n$ 個の整数を含む $n$ 行を出力してください。$i$ 行目の $j$ 列目には、あなたの答えで $p_k$ がマス $(i,j)$ となる整数 $k$ を一つ出力してください。

条件を満たす答えが複数ある場合は、そのうちのいずれかを出力してください。

入出力例

入力 1

8

出力 1

YES
1 7 25 26 8 27 37 38
2 60 23 33 59 48 42 41
5 6 16 34 57 46 45 39
3 21 22 52 58 28 43 53
64 19 24 35 9 47 36 54
62 61 15 32 10 49 31 40
4 18 17 51 56 50 44 55
63 20 14 13 11 29 30 12

注記

problem_20738_c0347100bcf3efa88ce4e65e034445fa.png

1 回目の移動(薄い色)から、開始位置に戻る 64 回目の移動(濃い色)まで。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.