답안 #600041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600041 2022-07-20T12:07:48 Z Piokemon Furniture (JOI20_furniture) C++17
0 / 100
100 ms 584 KB
#include <bits/stdc++.h>
using namespace std;

int d[4][2] = {{-1,0},{1,0},{0,1},{0,-1}};
bool grid[109][109];
int odw[109][109];

void dfs(int x, int y){
    odw[x][y] = 1;
    for (int z=0;z<4;z++){
        if (odw[x+d[z][0]][y+d[z][1]] == 0 && !grid[x+d[z][0]][y+d[z][1]]){
            dfs(x+d[z][0], y+d[z][1]);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,q,a,b;
    cin >> n >> m;
    for (int x=0;x<=m;x++){
        grid[0][x] = 1;
        grid[n+1][x] = 1;
    }
    for (int x=1;x<=n;x++){
        grid[x][0] = 1;
        grid[x][m+1] = 1;
        for (int y=1;y<=m;y++){
            cin >> grid[x][y];
        }
    }
    cin >> q;
    while(q--){
        cin >> a >> b;
        for (int x=1;x<=n;x++){
            for (int y=1;y<=m;y++){
                odw[x][y] = 0;
            }
        }
        grid[a][b] = 1;
        dfs(1,1);
        if (odw[n][m]){
            cout << "1\n";
        }
        else{
            cout << "0\n";
            grid[a][b] = 0;
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 584 KB Output is correct
2 Incorrect 100 ms 508 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 584 KB Output is correct
2 Incorrect 100 ms 508 KB Output isn't correct
3 Halted 0 ms 0 KB -