QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 2048 MB 總分: 100

#8098. XCopy

统计

今天,编程课结束时,老师布置了一项非常困难的家庭作业,于是孩子们决定作弊,互相抄袭。然而,为了不被发现作弊,他们必须表现得聪明一点。

班级里有 $N \times M$ 名学生,坐在 $N$ 行 $M$ 列的 $N \times M$ 个座位上。如果两个孩子坐在彼此左侧、右侧、上方或下方的相邻座位上,则称他们为邻居。作业要求找到一个特定的非负整数。为了不被发现作弊,所有这些整数必须各不相同。此外,孩子们非常懒惰,因此他们在从邻居那里抄袭答案时几乎不会修改答案。更准确地说,每个孩子的答案与他任何邻居的答案相比,在二进制表示下恰好有一位不同。例如,3 和 2 在二进制下恰好有一位不同,而 2 和 4 则不是。

孩子们不想引起怀疑,因此他们希望所有人给出的最大答案尽可能小。给定 $N$ 和 $M$,请创建一个答案配置,使得老师不会发现孩子们作弊了。

输入格式

输入包含一行,由空格分隔的 $N$ 和 $M$。

输出格式

输出包含孩子们的最优答案。输出应有 $N$ 行,每行包含 $M$ 个由空格分隔的非负整数。这些整数代表根据孩子们在班级中的座位所对应的答案。

数据范围

  • $1 \le N, M \le 2000$
# 分值 数据范围
1 7 $N = 1$
2 9 $N, M$ 为 2 的幂
3 14 $N$ 为 2 的幂
4 70 无其他限制

子任务

本题接受部分解,将根据答案与最优答案的接近程度进行部分评分,评分公式如下:

$$S \cdot \max \left( 1 - \sqrt{\frac{G - 1}{O - 1}}, 0 \right)$$

其中: $S$ 为测试点的分值, $G$ 为给出的答案(最大值), * $O$ 为最优答案(最大值)。

警告!如果不符合输出格式(所有数字必须不同,且任意两个相邻数字在二进制表示下恰好有 1 位不同)的解,在该测试点上将得 0 分。

样例

样例输入 1

3 3

样例输出 1

5 4 6
1 0 2
9 8 10

说明

在本节中,数字后的下标表示该数字的进制。例如,8 可以写成 $8_{10} = 1000_2$。

学生的一组最优答案如下表所示:

$0101_2 = 5_{10}$ $0100_2 = 4_{10}$ $0110_2 = 6_{10}$
$0001_2 = 1_{10}$ $0000_2 = 0_{10}$ $0010_2 = 2_{10}$
$1001_2 = 9_{10}$ $1000_2 = 8_{10}$ $1010_2 = 10_{10}$

观察可知,任意两个相邻座位上的数字恰好有一位不同。该解的最大值为 10,这是最优答案。显然其他解也是最优的——例如将上述解垂直或水平翻转。

另一个最大值为 15 的部分解为:

$0110_2$ $0111_2$ $0101_2$
$1110_2$ $1111_2$ $1101_2$
$1010_2$ $1011_2$ $1001_2$

根据评分公式,该解在该测试点上将获得 59.1% 的分数。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.