QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#20031. 美しい正方形

Statistics

Harry は絵を描くことが好きである。Harry は正方形も好きである。今日は Harry が正方形を描く。

Harry の正方形は $n\cdot n$ 個の単位正方形に分割できる。行に上から下へ $1$ から $n$ まで番号を付ける。同様に、列に左から右へ $1$ から $n$ まで番号を付ける。

Harry は各単位正方形に $1$ から $n\cdot n$ までの整数を 1 つ書く。Harry によれば、正方形が美しいのは、次の条件を満たす場合、かつその場合に限る。

  • $1$ から $n\cdot n$ までの各整数が、ちょうど 1 つのマスに書かれている。
  • $1$ から $n\cdot n-1$ までの各 $i$ について、整数 $i$ と $i+1$ は辺を共有する 2 つの単位正方形に書かれていなければならない。

Harry はすでに大きさ $n$ の正方形を描き、あるマスに整数 $1$ を書いた。Harry が $2$ から $n\cdot n$ までの整数を書いて、美しい正方形を作れるように手伝ってほしい。

入力

入力の最初の行には、テストケース数を表す整数 $t$ ($1\le t\le100$) が含まれる。続いて $t$ 個のテストケースが与えられ、各テストケースは 1 行に 3 つの整数 $n$, $r$, $c$ ($1\le r,c\le n\le100$) を含む。ここで:

  • $n$ は Harry が描いた正方形の大きさを表す。
  • $r$ と $c$ は整数 $1$ を含む単位正方形の行と列である。

出力

各テストケースについて:

  • 美しい正方形を作れない場合は、NO を含む 1 行を出力する。
  • それ以外の場合は YES を出力し、続いて美しい正方形を表す $n$ 行を出力する。各行はちょうど $n$ 個の整数を含む。解が複数ある場合は、どれを出力してもよい。

入出力例

入力 1

2
4 1 1
5 1 2

出力 1

YES
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
NO

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.