Submission #888929

#TimeUsernameProblemLanguageResultExecution timeMemory
888929nguyentunglamSeats (IOI18_seats)C++17
5 / 100
4038 ms40516 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; const int N = 1e6 + 10, M = 1010; int r[N], c[N]; int h, w; bool a[M][M]; void give_initial_chart(int _h, int _w, vector<int> _r, vector<int> _c) { // for(int i = 0; i < _h * _w; i++) cout << _r[i] << " " << _c[i] << endl; h = _h; w = _w; for(int i = 0; i < h * w; i++) r[i] = _r[i] + 1, c[i] = _c[i] + 1; // for(int i = 0; i < h * w; i++) cout << r[i] << " " << c[i] << endl; } int calc (int x, int y) { return a[x][y] + a[x][y + 1] + a[x + 1][y] + a[x + 1][y + 1]; } int swap_seats(int x, int y) { swap(r[x], r[y]); swap(c[x], c[y]); int ans = 0; for(int val = 0; val < h * w; val++) { a[r[val]][c[val]] = 1; int match = 0; // cout << r[val] << " " << c[val] << endl; for(int i = 0; i <= h; i++) for(int j = 0; j <= w; j++) { int tmp = calc(i, j); if (tmp == 1) match++; if (tmp == 3) match = 1e9; } if (match == 4) ans++; } for(int val = 0; val < h * w; val++) a[r[val]][c[val]] = 0; return ans; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int _h, _w; cin >> _h >> _w; vector<int> _r(_h * _w), _c(_h * _w); for(int i = 0; i < _h; i++) for(int j = 0; j < _w; j++) { int x; cin >> x; _r[x] = i; _c[x] = j; } give_initial_chart(_h, _w, _r, _c); int q; cin >> q; while (q--) { int a, b; cin >> a >> b; cout << swap_seats(a, b) << endl; } } #endif // ngu
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...