Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- vector <vector <int> > mtr;
- int n;
- bool sh = 1;
- vector <int> split(string s) {
- int l = s.size();
- vector <int> a;
- string x = "";
- for (int i = 0; i < l; ++i) {
- if (s[i] == ' ') {
- a.push_back(stoi(x));
- x = "";
- } else {
- x += s[i];
- }
- }
- if (x != "") {
- a.pb(stoi(x));
- }
- return a;
- }
- bool ok(int x, int y, auto a, auto b) {
- return a[x] == a[y] && b[x] == b[y];
- }
- void wrk(int x, int y, auto a, auto b) {
- for (int i = 0; i < n; ++i) {
- mtr[i][y] = a[i];
- }
- for (int j = 0; j < n; ++j) {
- mtr[x][j] = b[j];
- }
- }
- void get(int x, int y) {
- vector <vector <int> > ala, alb;
- vector <int> a, b;
- for (int j = 0; j < n; ++j) {
- a.pb(mtr[x][j]);
- }
- ala.push_back(a);
- reverse(a.begin(), a.end());
- ala.push_back(a);
- for (int i = 0; i < n; ++i) {
- b.pb(mtr[i][y]);
- }
- alb.push_back(b);
- reverse(b.begin(), b.end());
- alb.push_back(b);
- for (auto a: ala) {
- for (auto b: alb) {
- if (ok(x, y, a, b)) {
- if (sh) {
- cout << "OK\n";
- cout << "x y = " << x << ' ' << y << "\n";
- }
- wrk(x, y, a, b);
- cvv(mtr);
- exit(0);
- }
- }
- }
- }
- int main() {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- string s;
- getline(cin, s);
- vector <int> a = split(s);
- n = a.size();
- /*if (sh) {
- cout << "n a \n";
- cout << n << "\n";
- cv(a);
- }*/
- mtr.resize(n, vector <int> (n));
- mtr[0] = a;
- for (int i = 1; i < n; ++i) {
- for (int j = 0; j < n; ++j ) {
- cin >> mtr[i][j];
- }
- }
- vector <int> sx(n, 0), sy(n, 0);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- sx[i] += mtr[i][j];
- sy[j] += mtr[i][j];
- }
- }
- if (sh) {
- cout << "sx sy\n";
- cv(sx);
- cv(sy);
- }
- vector <pii> ox(n), oy(n);
- for (int i = 0; i < n; ++i) {
- ox[i] = {sx[i], i};
- oy[i] = {sy[i], i};
- }
- sort(ox.begin(), ox.end());
- sort(oy.begin(), oy.end());
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if (ox[i].first != oy[j].first) {
- continue;
- }
- get(ox[i].second, oy[j].second);
- }
- }
- cout << "NO\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement