QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#9415. 矩阵

统计

构造一个 $n$ 行 $n$ 列的矩阵,满足以下所有约束:

  • 矩阵中的元素为 $1$ 到 $2n$ 之间的整数(包含 $1$ 和 $2n$)。
  • $1$ 到 $2n$ 之间的每个整数(包含 $1$ 和 $2n$)在矩阵中至少出现一次。
  • 设 $a_{i,j}$ 为第 $i$ 行第 $j$ 列的元素,存在且仅存在一个整数四元组 $(x, y, z, w)$ 满足:
    • $1 \le x < z \le n$。
    • $1 \le y < w \le n$。
    • $a_{x,y}, a_{x,w}, a_{z,y}, a_{z,w}$ 两两不同。

输入格式

每个测试文件中仅包含一组测试数据。 输入的第一行包含一个整数 $n$ ($2 \le n \le 50$),表示矩阵的大小。

输出格式

如果可以构造出这样的矩阵,首先在第一行输出 Yes。然后输出 $n$ 行,其中第 $i$ 行包含 $n$ 个整数 $a_{i,1}, a_{i,2}, \dots, a_{i,n}$ ($1 \le a_{i,j} \le 2n$),并用空格分隔,其中 $a_{i,j}$ 是第 $i$ 行第 $j$ 列的元素。如果存在多个合法的答案,你可以输出其中任意一个。 如果无法构造出这样的矩阵,仅在第一行输出 No

样例

输入 1

2

输出 1

Yes
1 2
3 4

输入 2

3

输出 2

Yes
3 2 6
4 3 3
3 1 5

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.