Submission #875649

#TimeUsernameProblemLanguageResultExecution timeMemory
875649nguyentunglamSeats (IOI18_seats)C++17
0 / 100
4042 ms40496 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 = 1e3 + 10;

int r[N], c[N];

bool a[M][M];
int h, w;

void give_initial_chart(int _h, int _w, vector<int> _r, vector<int> _c) {
   h = _h; w = _w;
   for(int i = 0; i < h * w; i++) r[i + 1] = _r[i], c[i + 1] = _c[i], r[i + 1]++, c[i + 1]++;
}

bool check (int x, int y) {
  return a[x][y] + a[x - 1][y] + a[x][y - 1] + a[x - 1][y - 1] == 1;
}

int swap_seats(int x, int y) {
  x++; y++;
  swap(r[x], r[y]);
  swap(c[x], c[y]);

  int ans = 0;

  for(int i = 1; i <= h * w; i++) {
    a[r[i]][c[i]] = 1;
    int tmp = 0;
    for(int i = 1; i <= h + 1; i++) for(int j = 1; j <= w + 1; j++) tmp += check(i, j);
    if (tmp == 4) ans++;
  }

  for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++) a[i][j] = 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...