QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#2808. 园艺

الإحصائيات

高原的魔女 Azusa 想要和她的朋友 Laika 一起进行一项有趣的活动:园艺。她们想要建造一个 $N$ 米高、$M$ 米宽的矩形花园。花园被划分为 $1$ 米 $\times$ $1$ 米的方格。问题是:她们应该种植什么花?

Laika 找到了 $K$ 种不同类型的花。Azusa 和 Laika 将在每个 $1$ 米 $\times$ $1$ 米的方格中种植一种花。此外,出于美观考虑,花园必须满足以下限制条件:

  1. 每种花在花园中必须至少出现一次。
  2. 对于种植了同种花的任意两个方格,必须存在一条路径连接它们,且该路径上的所有中间方格都种植同种花。例如,以下花园是不允许的:
  1. 任何方格必须恰好有两个相邻的方格种植了同种花。例如,以下花园是不允许的:

注意,在上述限制条件中,两个方格“相邻”当且仅当它们共享一条公共边(不仅仅是共享一个角);路径是指一系列相邻方格的序列。

给定 $T$ 组不同的 $N, M$ 和 $K$ 值。请帮助 Azusa 和 Laika 为每组测试用例创建满足条件的花园,或者告诉她们这是不可能的。

输入格式

输入的第一行包含整数 $T$。接下来有 $T$ 行,每行描述一个测试用例。每个测试用例包含三个整数 $N, M$ 和 $K$。

输出格式

按顺序输出每个测试用例的答案。对于一个测试用例,如果不存在解决方案,则输出一行 NO。否则,首先输出一行 YES,然后输出 $N \times M$ 个整数,排列为 $N$ 行 $M$ 列,描述所需的花园。输出的行和列对应花园的行和列,每个整数对应一个 $1$ 米 $\times$ $1$ 米的方格。这些整数代表种植在方格中的花卉类型,类型编号从 $1$ 到 $K$。如果存在多个正确的解决方案,你可以输出其中任意一个。

数据范围

  • $1 \le N, M \le 200\,000$
  • $1 \le K \le N \times M$
  • 令 $S$ 为文件中所有存在答案(即输出不为 NO)的测试用例的 $N \times M$ 之和。
  • $S \le 200\,000$
# 分数 限制
1 5 $N, M \le 4$
2 6 $N \le 4$
3 10 $N \le 6$
4 18 $N = M$
5 39 $K$ 在 $1$ 到 $N \times M$ 之间均匀随机选择
6 22 无额外限制

样例

样例输入 1

5
2 2 2
2 2 1
4 4 4
4 4 2
4 6 3

样例输出 1

NO
YES
1 1
1 1
YES
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
YES
1 1 1 1
1 2 2 1
1 2 2 1
1 1 1 1
YES
1 1 1 1 1 1
1 2 2 3 3 1
1 2 2 3 3 1
1 1 1 1 1 1

说明

对于第一个测试用例,我们注意到不存在 $2 \times 2$ 且种植 $2$ 种花的花园。因此我们输出 NO。其他花园如下图所示:

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.