#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int ma[110][110];
int X[3]={0,1};
int Y[3]={1,0};
int n,m;
bool vis[110][110];
bool floyd(int x,int y){
memset(vis,0,sizeof vis);
vis[0][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(vis[i][j]){
for(int k=0;k<2;k++){
int xi=i+X[k];
int yi=j+Y[k];
if(xi<n && xi<m && ma[xi][yi]!=1) vis[xi][yi]=1;
}
}
}
}
return vis[n-1][m-1];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin>>ma[i][j];
int q;
cin>>q;
for(int i=0;i<q;i++){
int a,b;
cin>>a>>b;
a--; b--;
ma[a][b]=1;
if(floyd(0,0)) cout<<"1\n";
else{
cout<<"0\n";
ma[a][b]=0;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
332 KB |
Output is correct |
2 |
Incorrect |
52 ms |
368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
332 KB |
Output is correct |
2 |
Incorrect |
52 ms |
368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |