QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 1024 MB Total points: 40

#5907. 割草机

Statistics

Alice 和 Bob 房前有一块 $N$ 米乘 $M$ 米的矩形草坪。每年他们都会尝试用有趣的图案来修剪草坪。过去他们用剪刀修剪,非常耗时;但现在他们有了一台带有多种设置的新型自动割草机,想要试用一下。

这台新型割草机的割草高度可以设置为 1 到 100 毫米之间的任意高度 $h$,它会将所经过之处所有高于 $h$ 的草剪到高度 $h$。操作时,你可以从草坪边缘的任意位置进入;割草机将沿垂直于进入边缘的直线行进,剪掉宽度为 1 米的草带,直到从草坪的另一侧离开。割草机的高度只能在它不在草坪上时进行设置。

Alice 和 Bob 有多种不同的草坪图案方案。对于每种方案,他们都想知道是否可以使用这台新割草机修剪出该图案。每个图案由草坪上每个 $1\text{m} \times 1\text{m}$ 方格的草高来描述。

草坪初始时全为 100 毫米高。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例的第一行包含两个整数:$N$ 和 $M$。接下来的 $N$ 行,每行包含 $M$ 个整数 $a_{i,j}$,其中 $a_{i,j}$ 描述了第 $i$ 行第 $j$ 列方格中草的期望高度。

输出格式

对于每个测试用例,输出一行 "Case #x: y",其中 $x$ 是测试用例编号(从 1 开始),如果可以使用割草机得到第 $x$ 个图案,则 $y$ 为 "YES",否则为 "NO"(引号仅用于清晰说明)。

数据范围

$1 \le T \le 100$。

小数据集(测试集 1 - 可见;10 分)

$1 \le N, M \le 10$。 $1 \le a_{i,j} \le 2$。

大数据集(测试集 2 - 隐藏;30 分)

$1 \le N, M \le 100$。 $1 \le a_{i,j} \le 100$。

样例

样例输入 1

3
3 3
2 1 2
1 1 1
2 1 2
5 5
2 2 2 2 2
2 1 1 1 2
2 1 2 1 2
2 1 1 1 2
2 2 2 2 2
1 3
1 2 1

样例输出 1

Case #1: YES
Case #2: NO
Case #3: YES

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.