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_67009724d540d55e4de15f398b219faf.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.