Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- const int N = 1e6+7;
- int n, m, c[2];
- bool bd[N];
- string s;
- int a[N], b[N];
- void solve() {
- cin >> n >> m;
- c[0] = -1;
- c[1] = -1;
- for (int i = 0; i < n; i++) {
- bd[i] = 0;
- int cnt = 0;
- for (int j = 0; j < m; j++) {
- cin >> a[i * m + j];
- b[i * m + j] = a[i * m + j];
- }
- sort(b + i * m, b + i * (m) + m);
- for (int j = 0; j < m; j++) {
- if (a[i * m + j] != b[i * m + j]) {
- bd[i] = 1;
- if (cnt == 2) {
- cout << "-1\n";
- return;
- }
- if (c[cnt] != -1 && c[cnt] != j) {
- cout << "-1\n";
- return;
- }
- c[cnt] = j;
- cnt++;
- }
- }
- }
- if (c[0] == -1) {
- cout << "1 1\n";
- return;
- }
- for (int i = 0; i < n; i++) {
- if (a[i * m + c[0]] != a[i * m + c[1]] && !bd[i]) {
- cout << "-1\n";
- return;
- }
- }
- cout << c[0] + 1 << " " << c[1] + 1 << "\n";
- }
- int main()
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- #else
- std::ios::sync_with_stdio(false);
- cin.tie(0);
- #endif
- int t;
- cin >> t;
- while (t--) {
- solve();
- //cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment