QOJ.ac

QOJ

총점: 100 출력 전용

#18055. 表格

통계

对于给定的整数 $M$,构建一个具有 $N$ 行和 $N$ 列的正方形表格($2 \le N \le 10$),其中填入十进制数字,并满足以下限制条件:

  • 由每行(从左到右)、每列(从上到下)以及两条对角线(从上到下)上的数字组成的 $N$ 位数必须是 $M$ 的倍数。
  • 这些 $N$ 位数不能以数字 0 开头。
  • 这些 $N$ 位数在表格中必须是唯一的(即不能重复出现)。

例如,当 $M = 2$ 时,一个有效的表格为:

2 3 4
5 6 6
8 2 0

以下表格对于 $M = 2$ 是无效的:

4

因为 $N < 2$;

2 0
4 8

因为最后一列($08$)和其中一条对角线($04$)组成的数字以数字 0 开头;

2 3 4
5 8 8
2 0 2

因为数字 $482$ 在表格中出现了两次(第三列和副对角线)。

并非总是可以解决此任务。例如,当 $M = 10$ 时,该任务无解。

输入格式

本题为提交答案题。你将获得十个输入文件 TABLEx.IN($1 \le x \le 10$),每个文件包含一个 $M$ 的值。

输出格式

你必须为每个测试点找到一个有效的表格,并将其写入对应的输出文件 TABLEx.OUT($1 \le x \le 10$)。

文件的第一行必须包含 $N$,即表格的行数和列数。

接下来的第 $i+1$ 行($1 \le i \le N$)必须包含表格第 $i$ 行的元素,为 $N$ 个数字,用空格隔开。

样例

输入样例 1

2

输出样例 1

3
2 3 4
5 6 6
8 2 0

说明

已知对于每个给定的测试输入,都至少存在一个解。

子任务

如果某个测试点没有输出文件,或者未满足上述任何条件,你将在该测试点获得 0 分。

否则,你在该测试点获得的分数将根据以下公式计算:

$$\text{maximum points for the test case} \cdot \frac{N_{\text{least among contestants}}}{N_{\text{yours}}}$$

并向下取整到最接近的整数。因此,你应该尝试在满足上述条件的前提下,寻找一个尺寸尽可能小的有效表格。


또는 파일을 하나씩 업로드:

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.