#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int ma[1010][1010];
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 && yi<m && !ma[xi][yi]) 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;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
588 KB |
Output is correct |
2 |
Correct |
39 ms |
720 KB |
Output is correct |
3 |
Correct |
110 ms |
680 KB |
Output is correct |
4 |
Correct |
159 ms |
704 KB |
Output is correct |
5 |
Correct |
196 ms |
716 KB |
Output is correct |
6 |
Correct |
310 ms |
728 KB |
Output is correct |
7 |
Correct |
162 ms |
716 KB |
Output is correct |
8 |
Correct |
161 ms |
724 KB |
Output is correct |
9 |
Correct |
251 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
588 KB |
Output is correct |
2 |
Correct |
39 ms |
720 KB |
Output is correct |
3 |
Correct |
110 ms |
680 KB |
Output is correct |
4 |
Correct |
159 ms |
704 KB |
Output is correct |
5 |
Correct |
196 ms |
716 KB |
Output is correct |
6 |
Correct |
310 ms |
728 KB |
Output is correct |
7 |
Correct |
162 ms |
716 KB |
Output is correct |
8 |
Correct |
161 ms |
724 KB |
Output is correct |
9 |
Correct |
251 ms |
716 KB |
Output is correct |
10 |
Execution timed out |
5080 ms |
564 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |