Submission #387502

# Submission time Handle Problem Language Result Execution time Memory
387502 2021-04-08T15:35:47 Z timmyfeng Furniture (JOI20_furniture) C++17
0 / 100
3 ms 748 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1000;

bool blocked_s[N][N], blocked_t[N][N];
int unblocked[2 * N], n, m;

void block_s(int x, int y) {
    unblocked[x + y] -= !blocked_t[x][y];
    blocked_s[x][y] = true;
    if (x < n - 1 && !blocked_s[x + 1][y] && (y == 0 || blocked_s[x + 1][y - 1])) {
        block_s(x + 1, y);
    }
    if (y < m - 1 && !blocked_s[x][y + 1] && (x == 0 || blocked_s[x - 1][y + 1])) {
        block_s(x, y + 1);
    }
}

void block_t(int x, int y) {
    unblocked[x + y] -= !blocked_s[x][y];
    blocked_t[x][y] = true;
    if (x > 0 && !blocked_t[x - 1][y] && (y == m - 1 || blocked_t[x - 1][y + 1])) {
        block_t(x - 1, y);
    }
    if (y > 0 && !blocked_t[x][y - 1] && (x == n - 1 || blocked_t[x + 1][y - 1])) {
        block_t(x, y - 1);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            int c;
            cin >> c;

            if (c == 1) {
                block_s(i, j);
                block_t(i, j);
            }

            ++unblocked[i + j];
        }
    }

    int q;
    cin >> q;

    while (q--) {
        int x, y;
        cin >> x >> y;
        --x, --y;

        if (blocked_s[x][y] || blocked_t[x][y]) {
            cout << 1 << "\n";
        } else if (unblocked[x + y] > 1) {
            cout << 1 << "\n";
            block_s(x, y);
            block_t(x, y);
        } else {
            cout << 0 << "\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Incorrect 3 ms 748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 492 KB Output is correct
2 Incorrect 3 ms 748 KB Output isn't correct
3 Halted 0 ms 0 KB -