This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |