#include <bits/stdc++.h>
using namespace std;
int d[2][2] = {{1,0},{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<2;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 |
16 ms |
340 KB |
Output is correct |
2 |
Correct |
14 ms |
340 KB |
Output is correct |
3 |
Correct |
56 ms |
468 KB |
Output is correct |
4 |
Correct |
96 ms |
436 KB |
Output is correct |
5 |
Correct |
100 ms |
340 KB |
Output is correct |
6 |
Correct |
178 ms |
444 KB |
Output is correct |
7 |
Correct |
72 ms |
452 KB |
Output is correct |
8 |
Correct |
93 ms |
456 KB |
Output is correct |
9 |
Correct |
212 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
340 KB |
Output is correct |
2 |
Correct |
14 ms |
340 KB |
Output is correct |
3 |
Correct |
56 ms |
468 KB |
Output is correct |
4 |
Correct |
96 ms |
436 KB |
Output is correct |
5 |
Correct |
100 ms |
340 KB |
Output is correct |
6 |
Correct |
178 ms |
444 KB |
Output is correct |
7 |
Correct |
72 ms |
452 KB |
Output is correct |
8 |
Correct |
93 ms |
456 KB |
Output is correct |
9 |
Correct |
212 ms |
444 KB |
Output is correct |
10 |
Incorrect |
221 ms |
772 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |