Advertisement
Korotkodul

швб_22-23_N4_new

Oct 23rd, 2022 (edited)
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.48 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 <int> a, b;
  89.     for (int j = 0; j < n; ++j) {
  90.         a.pb(mtr[x][j]);
  91.     }
  92.  
  93.     for (int i = 0; i < n; ++i) {
  94.         b.pb(mtr[i][y]);
  95.     }
  96.  
  97.     if (ok(x, y, a, b)) {
  98.         if (sh) {
  99.             cout << "OK\n";
  100.             cout << "x y = " << x << ' ' << y << "\n";
  101.             cout << "a b\n";
  102.             cv(a);
  103.             cv(b);
  104.             cout << "\n";
  105.         }
  106.         wrk(x, y, a, b);
  107.         cvv(mtr);
  108.         exit(0);
  109.     }
  110. }
  111.  
  112. int main() {
  113.     /*ios::sync_with_stdio(0);
  114.     cin.tie(0);
  115.     cout.tie(0);*/
  116.     string s;
  117.     getline(cin, s);
  118.     vector <int> a = split(s);
  119.     n = a.size();
  120.     /*if (sh) {
  121.         cout << "n a \n";
  122.         cout << n << "\n";
  123.         cv(a);
  124.     }*/
  125.  
  126.     mtr.resize(n, vector <int> (n));
  127.     mtr[0] = a;
  128.     for (int i = 1; i < n; ++i) {
  129.         for (int j = 0; j < n; ++j ) {
  130.             cin >> mtr[i][j];
  131.         }
  132.     }
  133.     if (sh) {
  134.         cout << "mtr\n";
  135.         cvv(mtr);
  136.     }
  137.     vector <int> sx(n, 0), sy(n, 0);
  138.     for (int i = 0; i < n; ++i) {
  139.         for (int j = 0; j < n; ++j) {
  140.             sx[i] += mtr[i][j];
  141.             sy[j] += mtr[i][j];
  142.         }
  143.     }
  144.     if (sh) {
  145.         cout << "sx sy\n";
  146.         cv(sx);
  147.         cv(sy);
  148.     }
  149.     vector <pii> ox(n), oy(n);
  150.     for (int i = 0; i < n; ++i) {
  151.         ox[i] = {sx[i], i};
  152.         oy[i] = {sy[i], i};
  153.     }
  154.     sort(ox.begin(), ox.end());
  155.     sort(oy.begin(), oy.end());
  156.     if (sh) {
  157.         cout << "ox\n";
  158.         cvp(ox);
  159.         cout << "oy\n";
  160.         cvp(oy);
  161.     }
  162.     for (int i = 0; i < n; ++i) {
  163.         for (int j = 0; j < n; ++j) {
  164.             if (ox[i].first != oy[j].first) {
  165.                 continue;
  166.             }
  167.             get(ox[i].second, oy[j].second);
  168.         }
  169.     }
  170.     cout << "NO\n";
  171. }
  172. /*
  173. 1 2 1 1 1
  174. 3 1 1 1 1
  175. 1 1 1 4 1
  176. 1 1 1 1 5
  177. 1 1 6 1 1
  178.  
  179. 1 3 2
  180. 10 1 1
  181. 1 4 3
  182. here is mistake
  183.  
  184. */
  185.  
  186.  
  187.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement