CF1684C.Column Swapping

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a grid with nn rows and mm columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each 1≤i≤n1 \le i \le n and 2≤j≤m2 \le j \le m the following holds: ai,j≥ai,j−1a_{i,j} \ge a_{i, j-1}.

You have to to do the following operation exactly once: choose two columns with indexes ii and jj (not necessarily different), 1≤i,j≤m1 \le i, j \le m, and swap them.

You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped.

给你一个 nn 行 mm 列的网格,每个格子中写有一个正整数。我们称一个网格是“好的”,当且仅当每一行中的数字序列均以非递减顺序排列。即:对每个 1≤i≤n1 \le i \le n 和 2≤j≤m2 \le j \le m,均满足 ai,j≥ai,j−1a_{i,j} \ge a_{i, j-1}。

你必须恰好执行一次如下操作:选择两个列(列索引为 ii 和 jj,二者可以相同),其中 1≤i,j≤m1 \le i, j \le m,并将这两列交换。

你需要判断:是否有可能通过一次列交换使得网格变为“好的”;若可能,请找出需要交换的两列。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). Description of the test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5) — the number of rows and columns respectively.

Each of the next nn rows contains mm integers, jj-th element of ii-th row is ai,ja_{i,j} (1≤ai,j≤1091 \le a_{i,j} \le 10^9) — the number written in the jj-th cell of the ii-th row.

It's guaranteed that the sum of n⋅mn \cdot m over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5),分别表示行数和列数。

接下来的 nn 行中,每行包含 mm 个整数;第 ii 行的第 jj 个元素为 ai,ja_{i,j}(1≤ai,j≤1091 \le a_{i,j} \le 10^9),表示第 ii 行第 jj 列单元格中所写的数字。

保证所有测试用例中 n⋅mn \cdot m 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

If after the swap it is impossible to get a good grid, output −1-1.

In the other case output 22 integers — the indices of the columns that should be swapped to get a good grid.

If there are multiple solutions, print any.

如果交换后无法得到一个好网格,则输出 −1-1。

否则,输出 22 个整数——应交换的两列的下标,以得到一个好网格。

如果有多个解,输出任意一个即可。

输入输出样例

  • 输入#1

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

    输出#1

    1 1
    -1
    1 2
    1 3
    1 1

说明/提示

In the first test case the grid is initially good, so we can, for example, swap the first column with itself.

In the second test case it is impossible to make the grid good.

In the third test case it is needed to swap the first and the second column, then the grid becomes good.

在第一个测试用例中,网格初始即为“好”的,因此我们可以例如将第一列与自身交换。

在第二个测试用例中,无法使网格变为“好”的。

在第三个测试用例中,需要交换第一列和第二列,之后网格即变为“好”的。

输入解题思路,AI测评打分。不知道怎么写?

首页