답안 #684093

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684093 2023-01-20T10:58:10 Z Darren0724 Furniture (JOI20_furniture) C++17
0 / 100
5 ms 340 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> cnt(2050);
vector<vector<int>> v;
void dfs(int a,int b){
    v[a][b]=1;
    cnt[a+b]--;
    if(v[a-1][b+1]){
        if(v[a][b+1]==0){
            dfs(a,b+1);
        }
        if(v[a-1][b]==0){
            dfs(a-1,b);
        }
    }
    if(v[a+1][b-1]){
        if(v[a+1][b]==0){
            dfs(a+1,b);
        }
        if(v[a][b-1]==0){
            dfs(a,b-1);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin>>n>>m;
    v.resize(n+2,vector<int>(m+2,1));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cnt[i+j]++;
            v[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int p;cin>>p;
            if(p==1){
                cnt[i+j]--;
                dfs(i,j);
            }
        }
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
        int a,b;cin>>a>>b;
        if(v[a][b]==1){
            cout<<1<<endl;
            continue;
        }
        if(cnt[a+b]<=1){
            cout<<0<<endl;
        }
        else{
            cout<<1<<endl;
            dfs(a,b);
        }
    }
    /*for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cout<<v[i][j]<<' ';
        }
        cout<<endl;
    }*/

    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 5 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 5 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -