Universal Cup Judging System

Universal Cup

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓
Statistiques

$n$ 行 $n$ 列のグリッドを構築する問題です。グリッドの各セルには整数が配置されており、$a_{i,j}$ は $i$ 行 $j$ 列目のセルにある整数を表します。$1$ から $n^2$ までの各整数は、グリッド内にちょうど一度ずつ現れます。

ある整数 $x$ がこのグリッドの「ビンゴ整数」であるとは、以下の2つの条件のうち少なくとも一方が満たされることを指します。

  • その行のすべてのセルに含まれる整数が $x$ 以下であるような行が少なくとも1つ存在する。
  • その列のすべてのセルに含まれる整数が $x$ 以下であるような列が少なくとも1つ存在する。

グリッドには複数のビンゴ整数が存在し得ますが、この問題では最小のビンゴ整数のみを考えます。

整数 $n$ と $k$ が与えられます。最小のビンゴ整数がちょうど $k$ となるような $n$ 行 $n$ 列のグリッドを構築してください。

入力

入力は複数のテストケースから構成されます。最初の行にはテストケースの数 $T$ ($1 \le T \le 50$) が含まれます。各テストケースは以下の形式です。

最初の行には、2つの整数 $n$ と $k$ ($1 \le n \le 50, 1 \le k \le n^2$) が含まれます。

出力

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

  • 最小のビンゴ整数が $k$ となるような $n$ 行 $n$ 列のグリッドを構築することが可能な場合、まず1行目に Yes と出力してください。続いて $n$ 行を出力してください。各行には、その行の整数 $a_{i,1}, a_{i,2}, \dots, a_{i,n}$ をスペース区切りで出力してください。$1$ から $n^2$ までの各整数がグリッド内にちょうど一度ずつ現れる必要があることに注意してください。条件を満たす答えが複数存在する場合は、そのうちのどれを出力しても構いません。
  • 答えを見つけることが不可能な場合は、1行目に No と出力してください。

入出力例

入力 1

4
3 5
4 10
5 2
1 1

出力 1

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

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.