QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#8474. 矩阵与和

统计

给定一个正整数 $n$,你需要构造一个 $n \times n$ 的整数矩阵 $M$,满足以下条件:

  • 对于所有元素 $M_{i,j}$ ($1 \le i, j \le n$),其绝对值满足 $|M_{i,j}| \le 1$。
  • 行和与列和 $R_1, R_2, \dots, R_n, C_1, C_2, \dots, C_n$ 两两互不相同,其中 $R_x = \sum_{i=1}^n M_{x,i}$ 且 $C_x = \sum_{i=1}^n M_{i,x}$。

可能存在多个解,也可能无解。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 1000$)。

输出格式

如果存在解,第一行输出字符串 “Yes”(不含引号),否则输出 “No”(不含引号)。

若存在解,接下来输出 $n$ 行,每行包含 $n$ 个整数,表示你构造的矩阵 $M$。

如果存在多个解,输出其中任意一个即可。

样例

输入 1

2

输出 1

Yes
1 0
1 -1

输入 2

1

输出 2

No

说明

  • 在第一个样例中,$R_1 = 1, R_2 = 0, C_1 = 2, C_2 = -1$,它们互不相同。
  • 在第二个样例中,$R_1 = C_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.