Submission #856977

#TimeUsernameProblemLanguageResultExecution timeMemory
856977nguyentunglamSeats (IOI18_seats)C++17
11 / 100
4070 ms41180 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; int r[N], c[N]; int h, w; 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], c[i] = _c[i]; // for(int i = 0; i < h * w; i++) cout << r[i] << " " << c[i] << endl; } int swap_seats(int a, int b) { swap(r[a], r[b]); swap(c[a], c[b]); int up = 1e9, down = 0, leftt = 1e9, rightt = 0, ans = 0; for(int i = 0; i < h * w; i++) { // cerr << i << endl; up = min(up, r[i]); down = max(down, r[i]); leftt = min(leftt, c[i]); rightt = max(rightt, c[i]); // cout << r[i] << " " << c[i] << endl; // cout << up << " " << down << " " << leftt << " " << rightt << " " << i << endl; if ((down - up + 1) * (rightt - leftt + 1) == i + 1) { ans++; } } 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...