Submission #856973

# Submission time Handle Problem Language Result Execution time Memory
856973 2023-10-05T03:01:42 Z nguyentunglam Seats (IOI18_seats) C++17
0 / 100
4000 ms 47556 KB
#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 time Memory Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4093 ms 47556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 4052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -