Advertisement
Korotkodul

ШВБ_22-23_N4

Oct 23rd, 2022 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. vector <vector <int> > mtr;
  51. int n;
  52. bool sh = 1;
  53.  
  54.  
  55. vector <int> split(string s) {
  56.     int l = s.size();
  57.     vector <int> a;
  58.     string x = "";
  59.     for (int i = 0; i < l; ++i) {
  60.         if (s[i] == ' ') {
  61.             a.push_back(stoi(x));
  62.             x = "";
  63.         } else {
  64.             x += s[i];
  65.         }
  66.     }
  67.     if (x != "") {
  68.         a.pb(stoi(x));
  69.     }
  70.     return a;
  71. }
  72.  
  73. bool ok(int x, int y, auto a, auto b) {
  74.     return a[x] == a[y] && b[x] == b[y];
  75. }
  76.  
  77. void wrk(int x, int y, auto a, auto b) {
  78.     for (int i = 0; i < n; ++i) {
  79.         mtr[i][y] = a[i];
  80.     }
  81.     for (int j = 0; j < n; ++j) {
  82.         mtr[x][j] = b[j];
  83.     }
  84. }
  85.  
  86.  
  87. void get(int x, int y) {
  88.     vector <vector <int> > ala, alb;
  89.     vector <int> a, b;
  90.     for (int j = 0; j < n; ++j) {
  91.         a.pb(mtr[x][j]);
  92.     }
  93.     ala.push_back(a);
  94.     reverse(a.begin(), a.end());
  95.     ala.push_back(a);
  96.  
  97.     for (int i = 0; i < n; ++i) {
  98.         b.pb(mtr[i][y]);
  99.     }
  100.     alb.push_back(b);
  101.     reverse(b.begin(), b.end());
  102.     alb.push_back(b);
  103.     for (auto a: ala) {
  104.         for (auto b: alb) {
  105.             if (ok(x, y, a, b)) {
  106.                 if (sh) {
  107.                     cout << "OK\n";
  108.                     cout << "x y = " << x << ' ' << y << "\n";
  109.                 }
  110.                 wrk(x, y, a, b);
  111.                 cvv(mtr);
  112.                 exit(0);
  113.             }
  114.         }
  115.     }
  116. }
  117.  
  118. int main() {
  119.     /*ios::sync_with_stdio(0);
  120.     cin.tie(0);
  121.     cout.tie(0);*/
  122.     string s;
  123.     getline(cin, s);
  124.     vector <int> a = split(s);
  125.     n = a.size();
  126.     /*if (sh) {
  127.         cout << "n a \n";
  128.         cout << n << "\n";
  129.         cv(a);
  130.     }*/
  131.     mtr.resize(n, vector <int> (n));
  132.     mtr[0] = a;
  133.     for (int i = 1; i < n; ++i) {
  134.         for (int j = 0; j < n; ++j ) {
  135.             cin >> mtr[i][j];
  136.         }
  137.     }
  138.     vector <int> sx(n, 0), sy(n, 0);
  139.     for (int i = 0; i < n; ++i) {
  140.         for (int j = 0; j < n; ++j) {
  141.             sx[i] += mtr[i][j];
  142.             sy[j] += mtr[i][j];
  143.         }
  144.     }
  145.     if (sh) {
  146.         cout << "sx sy\n";
  147.         cv(sx);
  148.         cv(sy);
  149.     }
  150.     vector <pii> ox(n), oy(n);
  151.     for (int i = 0; i < n; ++i) {
  152.         ox[i] = {sx[i], i};
  153.         oy[i] = {sy[i], i};
  154.     }
  155.     sort(ox.begin(), ox.end());
  156.     sort(oy.begin(), oy.end());
  157.     for (int i = 0; i < n; ++i) {
  158.         for (int j = 0; j < n; ++j) {
  159.             if (ox[i].first != oy[j].first) {
  160.                 continue;
  161.             }
  162.             get(ox[i].second, oy[j].second);
  163.         }
  164.     }
  165.     cout << "NO\n";
  166. }
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement