GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Thursday, 19 May 2022

Column Swapping Codeforces Solution | Codeforces Problem Solution 2022

C. Column Swapping
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 1in and 2jm the following holds: ai,jai,j1.

You have to to do the following operation exactly once: choose two columns with indexes i and j (not necessarily different), 1i,jm, and swap them.

Solution Click Below:-  CLICK HERE

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.

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1t100).

 Description of the test cases follows.

The first line of each test case contains two integers n and m (1n,m2105) — 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 (1ai,j109) — the number written in the j-th cell of the i-th row.

It's guaranteed that the sum of nm over all test cases does not exceed 2105.

Output

If after the swap it is possible 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.


No comments:

Post a Comment