Column Swapping Codeforces Solution | Codeforces Problem Solution 2022
You are given a grid with rows and 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 and the following holds: .
You have to to do the following operation exactly once: choose two columns with indexes and (not necessarily different), , 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 ().
Description of the test cases follows.
The first line of each test case contains two integers and () — the number of rows and columns respectively.
Each of the next rows contains integers, -th element of -th row is () — the number written in the -th cell of the -th row.
It's guaranteed that the sum of over all test cases does not exceed .
If after the swap it is possible to get a good grid, output .
In the other case output integers — the indices of the columns that should be swapped to get a good grid.
If there are multiple solutions, print any.
No comments:
Post a Comment