Submission #1205882

#TimeUsernameProblemLanguageResultExecution timeMemory
1205882yogesh_saneFurniture (JOI20_furniture)C++20
0 / 100
1 ms324 KiB
#include <vector>
#include <iostream>
using namespace std;

vector<vector<bool>>vacant;
vector<int>diag;

void block(int x, int y){
    diag[x+y]--;
    vacant[x][y] = false;
    if(!vacant[x+1][y-1] && vacant[x+1][y])
        block(x+1,y);
    if(!vacant[x+1][y-1] && vacant[x][y-1])
        block(x,y-1);
    if(!vacant[x-1][y+1] && vacant[x][y+1])
        block(x,y+1);
    if(!vacant[x-1][y+1] && vacant[x-1][y])
        block(x-1,y);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vacant.assign(n+2, vector<bool>(m+2));
    diag.resize(n+m+1);
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++){
            diag[i+j]++;
            vacant[i][j] = true;
        }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            int blocked;
            cin >> blocked;
            if(blocked){
                block(i, j);
            }
        }
    }
    int q;
    cin >> q;
    while(q--){
        int x, y;
        cin >> x >> y;
        if(!vacant[x][y])
            cout << 1 << '\n';
        else if(diag[x+y] == 1)
            cout << 0 << '\n';
        else{
            cout << 1 << '\n';
            block(x, y);
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...