제출 #516302

#제출 시각아이디문제언어결과실행 시간메모리
516302jk410Furniture (JOI20_furniture)C++17
5 / 100
1989 ms760 KiB
#include <bits/stdc++.h>
using namespace std;
struct pos{
    int x,y;
};
int N,M,Q;
int A[101][101];
int dx[2]={0,1},dy[2]={1,0};
bool Visited[101][101];
bool f(){
    for (int i=1; i<=N; i++){
        for (int j=1; j<=M; j++)
            Visited[i][j]=false;
    }
    queue<pos> q;
    Visited[1][1]=true;
    q.push({1,1});
    while (!q.empty()){
        pos t=q.front();
        q.pop();
        for (int i=0; i<2; i++){
            int x=t.x+dx[i],y=t.y+dy[i];
            if (x>N||y>M||Visited[x][y]||A[x][y])
                continue;
            Visited[x][y]=true;
            q.push({x,y});
        }
    }
    return Visited[N][M];
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>M;
    for (int i=1; i<=N; i++){
        for (int j=1; j<=M; j++)
            cin>>A[i][j];
    }
    cin>>Q;
    while (Q--){
        int x,y;
        cin>>x>>y;
        A[x][y]=1;
        if (!f()){
            cout<<"0\n";
            A[x][y]=0;
        }
        else
            cout<<"1\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...