QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 512 MB Puntuación total: 100

#9788. Shreckless

Estadísticas

Lord Farquaad 拥有一个包含 $n$ 行 $m$ 列的整数表格 $a$。由于他有强迫症,他希望表格的每一行都是非递减的。

Shrek 觉得 Farquaad 对秩序的执着很荒谬,他有其他的打算。他可以任意重排每一列中的数字,并希望确保表格中没有任何一行是非递减的。他能实现他的目标吗?

如果一个数组 $a_1, a_2, \dots, a_k$ 满足 $a_1 \le a_2 \le \dots \le a_k$,则称其为非递减的。

输入格式

每个测试包含多个测试用例。第一行包含一个整数 $t$ —— 测试用例的数量。接下来是测试用例的描述。

每个测试用例的第一行包含两个整数 $n, m$ —— 表格的维度。

接下来的 $n$ 行中,第 $i$ 行包含 $m$ 个整数 $a_{i,1}, a_{i,2}, \dots, a_{i,m}$ —— 第 $i$ 行的元素。

数据范围

$1 \le t \le 2 \cdot 10^4$ $2 \le n, m \le 10^5$ $n \cdot m \le 2 \cdot 10^5$ 所有测试用例中 $n \cdot m$ 的总和不超过 $2 \cdot 10^5$ $1 \le a_{i,j} \le 10^9$

输出格式

对于每个测试用例,如果 Shrek 能使每一行都不是非递减的,输出 YES。否则,输出 NO。

样例

输入 1

3
2 2
69 69
2024 42
3 3
1 1 1
1 1 1
2 2 2
3 4
1 1 1 1
1 1 1 1
2 2 2 2

输出 1

YES
NO
YES

说明

在第一个测试用例中,初始时第一行是 $[69, 69]$,因此它是非递减的。然而,Shrek 可以交换第一列的数字,得到:

2024 69 69 42

在第二个测试用例中,无法通过重排各列使每一行都不是非递减的。

在第三个测试用例中,Shrek 可以将各列重排如下:

1 1 2 1 1 2 1 1 2 1 1 2

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.