CF1684C.Column Swapping
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a grid with n rows and m 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≤n and 2≤j≤m the following holds: ai,j≥ai,j−1 .
You have to to do the following operation exactly once: choose two columns with indexes i and j (not necessarily different), 1≤i,j≤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.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤100 ). Description of the test cases follows.
The first line of each test case contains two integers n and m ( 1≤n,m≤2⋅105 ) — the number of rows and columns respectively.
Each of the next n rows contains m integers, j -th element of i -th row is ai,j ( 1≤ai,j≤109 ) — the number written in the j -th cell of the i -th row.
It's guaranteed that the sum of n⋅m over all test cases does not exceed 2⋅105 .
输出格式
If after the swap it is impossible to get a good grid, output −1 .
In the other case output 2 integers — the indices of the columns that should be swapped to get a good grid.
If there are multiple solutions, print any.
输入输出样例
输入#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.