#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<vector<int>> inp(n+2, vector<int>(m+2, 0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++ ){
cin >> inp[i][j];
}
}
int q;
cin >> q;
for(int _ = 0; _ < q; _++){
int x, y;
cin >> x >> y;
vector<vector<bool>> p(n+2, vector<bool>(m+2, 0));
p[1][1] = 1;
inp[x][y] = 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++ ){
if(inp[i][j] == 0){
if(i!=1 || j!=1)
p[i][j] = p[i-1][j] || p[i][j-1];
}
}
}
if(p[n][m]) {
cout << "1\n";
}else{
cout << "0\n";
inp[x][y] = 0;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
67 ms |
348 KB |
Output is correct |
3 |
Correct |
88 ms |
348 KB |
Output is correct |
4 |
Correct |
216 ms |
344 KB |
Output is correct |
5 |
Correct |
202 ms |
348 KB |
Output is correct |
6 |
Correct |
265 ms |
600 KB |
Output is correct |
7 |
Correct |
253 ms |
344 KB |
Output is correct |
8 |
Correct |
272 ms |
344 KB |
Output is correct |
9 |
Correct |
244 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
344 KB |
Output is correct |
2 |
Correct |
67 ms |
348 KB |
Output is correct |
3 |
Correct |
88 ms |
348 KB |
Output is correct |
4 |
Correct |
216 ms |
344 KB |
Output is correct |
5 |
Correct |
202 ms |
348 KB |
Output is correct |
6 |
Correct |
265 ms |
600 KB |
Output is correct |
7 |
Correct |
253 ms |
344 KB |
Output is correct |
8 |
Correct |
272 ms |
344 KB |
Output is correct |
9 |
Correct |
244 ms |
548 KB |
Output is correct |
10 |
Correct |
4835 ms |
860 KB |
Output is correct |
11 |
Correct |
155 ms |
344 KB |
Output is correct |
12 |
Execution timed out |
5076 ms |
6356 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |