Submission #697154

# Submission time Handle Problem Language Result Execution time Memory
697154 2023-02-08T16:38:13 Z Shin Furniture (JOI20_furniture) C++14
100 / 100
280 ms 12820 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

const int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int N = 1e3 + 7;
int n, m, q;
bool a[N][N];
int cnt[N + N];

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i ++) {
    for (int j = 1; j <= m; j ++) {
      a[i][j] = 1;
      cnt[i + j] ++;
    }
  }

  auto rem = [&](int x, int y) {
    queue<pair<int, int>> q;
    q.emplace(x, y);
    while (!q.empty()) {
      tie(x, y) = q.front();
      q.pop();
      if (!a[x][y]) {
        continue;
      }
      a[x][y] = false;
      cnt[x + y] --;
      if (!a[x + 1][y - 1]) {
        q.emplace(x + 1, y);
        q.emplace(x, y - 1);
      } 
      if (!a[x - 1][y + 1]) {
        q.emplace(x - 1, y);
        q.emplace(x, y + 1);
      }
    }
  };

  for (int i = 1; i <= n; i ++) {
    for (int j = 1; j <= m; j ++) {
      char c; cin >> c;
      if (c == '1') {
        rem(i, j);        
      }
    }
  }
  cin >> q;
  while (q --) {
    int x, y; cin >> x >> y;
    if (cnt[x + y] == 1 && a[x][y]) {
      cout << 0 << '\n';
    } else {
      cout << 1 << '\n';
      rem(x, y);
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 476 KB Output is correct
10 Correct 8 ms 596 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 125 ms 5892 KB Output is correct
13 Correct 35 ms 3036 KB Output is correct
14 Correct 239 ms 10672 KB Output is correct
15 Correct 240 ms 10960 KB Output is correct
16 Correct 247 ms 11852 KB Output is correct
17 Correct 252 ms 12492 KB Output is correct
18 Correct 262 ms 12136 KB Output is correct
19 Correct 270 ms 12780 KB Output is correct
20 Correct 280 ms 12800 KB Output is correct
21 Correct 274 ms 12820 KB Output is correct