bibaboba12345

Untitled

May 19th, 2022
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. const int N = 1e6+7;
  11. int n, m, c[2];
  12. bool bd[N];
  13. string s;
  14. int a[N], b[N];
  15. void solve() {
  16. cin >> n >> m;
  17. c[0] = -1;
  18. c[1] = -1;
  19.  
  20. for (int i = 0; i < n; i++) {
  21. bd[i] = 0;
  22. int cnt = 0;
  23. for (int j = 0; j < m; j++) {
  24. cin >> a[i * m + j];
  25. b[i * m + j] = a[i * m + j];
  26. }
  27. sort(b + i * m, b + i * (m) + m);
  28. for (int j = 0; j < m; j++) {
  29. if (a[i * m + j] != b[i * m + j]) {
  30. bd[i] = 1;
  31. if (cnt == 2) {
  32. cout << "-1\n";
  33. return;
  34. }
  35. if (c[cnt] != -1 && c[cnt] != j) {
  36. cout << "-1\n";
  37. return;
  38. }
  39. c[cnt] = j;
  40. cnt++;
  41. }
  42. }
  43. }
  44. if (c[0] == -1) {
  45. cout << "1 1\n";
  46. return;
  47. }
  48. for (int i = 0; i < n; i++) {
  49. if (a[i * m + c[0]] != a[i * m + c[1]] && !bd[i]) {
  50. cout << "-1\n";
  51. return;
  52. }
  53. }
  54. cout << c[0] + 1 << " " << c[1] + 1 << "\n";
  55. }
  56.  
  57. int main()
  58. {
  59. #ifdef _DEBUG
  60. freopen("input.txt", "r", stdin);
  61. #else
  62. std::ios::sync_with_stdio(false);
  63. cin.tie(0);
  64. #endif
  65. int t;
  66. cin >> t;
  67. while (t--) {
  68. solve();
  69. //cout << "\n";
  70. }
  71. return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment