Universal Cup Judging System

Universal Cup

Límite de tiempo: 1.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

在這個問題中,你需要建構一個 $n$ 列 $n$ 行的網格。網格中的每個儲存格都有一個整數,其中 $a_{i,j}$ 表示位於第 $i$ 列第 $j$ 行的整數。從 $1$ 到 $n^2$ 的每個整數(包含 $1$ 與 $n^2$)在網格中恰好出現一次。

我們稱一個整數 $x$ 為該網格的「賓果整數」,若滿足以下兩個條件中的至少一個: 至少存在一列,該列中所有儲存格的整數都小於或等於 $x$。 至少存在一行,該行中所有儲存格的整數都小於或等於 $x$。

顯然一個網格可能有多個賓果整數,但在本題中,我們只對最小的賓果整數感興趣。

給定整數 $n$ 與 $k$,請建構一個 $n$ 列 $n$ 行的網格,使得其最小的賓果整數恰好為 $k$。

輸入格式

輸入包含多組測試資料。第一行包含一個整數 $T$ ($1 \le T \le 50$),表示測試資料的組數。對於每組測試資料: 第一行包含兩個整數 $n$ 與 $k$ ($1 \le n \le 50, 1 \le k \le n^2$)。

輸出格式

對於每組測試資料: 若能建構出一個 $n$ 列 $n$ 行的網格,使得其最小的賓果整數為 $k$,請先輸出一行 Yes。接著輸出 $n$ 行,其中第 $i$ 行包含 $n$ 個整數 $a_{i,1}, a_{i,2}, \dots, a_{i,n}$,以空格分隔,表示網格第 $i$ 列的整數。請記得從 $1$ 到 $n^2$ 的每個整數(包含 $1$ 與 $n^2$)必須在網格中恰好出現一次。若有多種合法的答案,你可以輸出其中任意一種。 若無法找到答案,請僅輸出一行 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.