답안 #684096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684096 2023-01-20T11:05:18 Z Darren0724 Furniture (JOI20_furniture) C++17
100 / 100
1449 ms 6472 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){
                if(v[i][j]==0){
                    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 Correct 6 ms 360 KB Output is correct
3 Correct 8 ms 340 KB Output is correct
4 Correct 16 ms 384 KB Output is correct
5 Correct 15 ms 340 KB Output is correct
6 Correct 17 ms 376 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
8 Correct 15 ms 340 KB Output is correct
9 Correct 14 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 6 ms 360 KB Output is correct
3 Correct 8 ms 340 KB Output is correct
4 Correct 16 ms 384 KB Output is correct
5 Correct 15 ms 340 KB Output is correct
6 Correct 17 ms 376 KB Output is correct
7 Correct 14 ms 384 KB Output is correct
8 Correct 15 ms 340 KB Output is correct
9 Correct 14 ms 340 KB Output is correct
10 Correct 34 ms 596 KB Output is correct
11 Correct 8 ms 340 KB Output is correct
12 Correct 467 ms 4832 KB Output is correct
13 Correct 56 ms 3884 KB Output is correct
14 Correct 1175 ms 5664 KB Output is correct
15 Correct 1219 ms 5572 KB Output is correct
16 Correct 1238 ms 5792 KB Output is correct
17 Correct 1330 ms 6232 KB Output is correct
18 Correct 1293 ms 6028 KB Output is correct
19 Correct 1449 ms 6400 KB Output is correct
20 Correct 1327 ms 6296 KB Output is correct
21 Correct 1395 ms 6472 KB Output is correct