Submission #888580

# Submission time Handle Problem Language Result Execution time Memory
888580 2023-12-17T21:34:28 Z box Furniture (JOI20_furniture) C++17
100 / 100
205 ms 16220 KB
#include <bits/stdc++.h>
using namespace std;

#define ar array
#define sz(v) int(std::size(v))
using i64 = long long;

const int N = 1e3;

int n, m, q;
int c[N][N], cnt[N * 2];

bool del(int i, int j) {
    if (!c[i][j] || cnt[i + j] == 1) return false;
    cnt[i + j]--;
    c[i][j] = 0;
    if (i + 1 < n && (j == 0 || c[i + 1][j - 1] == 0)) del(i + 1, j);
    if (i - 1 >= 0 && (j == m - 1 || c[i - 1][j + 1] == 0)) del(i - 1, j);
    if (j + 1 < m && (i == 0 || c[i - 1][j + 1] == 0)) del(i, j + 1);
    if (j - 1 >= 0 && (i == n - 1 || c[i + 1][j - 1] == 0)) del(i, j - 1);
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> m;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) c[i][j] = 1, cnt[i + j]++;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
        int a; cin >> a;
        if (a) del(i, j);
    }
    cin >> q;
    while (q--) {
        int x, y;
        cin >> x >> y, x--, y--;
        del(x, y);
        cout << 1 - c[x][y] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2780 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2792 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 2 ms 2652 KB Output is correct
4 Correct 2 ms 2780 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 3 ms 2796 KB Output is correct
7 Correct 3 ms 2792 KB Output is correct
8 Correct 2 ms 2648 KB Output is correct
9 Correct 3 ms 2652 KB Output is correct
10 Correct 7 ms 3024 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 113 ms 8980 KB Output is correct
13 Correct 40 ms 5904 KB Output is correct
14 Correct 172 ms 13620 KB Output is correct
15 Correct 179 ms 13916 KB Output is correct
16 Correct 182 ms 14712 KB Output is correct
17 Correct 197 ms 15608 KB Output is correct
18 Correct 193 ms 15188 KB Output is correct
19 Correct 199 ms 15952 KB Output is correct
20 Correct 205 ms 16220 KB Output is correct
21 Correct 197 ms 15952 KB Output is correct