#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, m;
vector <vector<bool>> v, bl;
bool dfs(int x, int y){
if(x < 0 || x >= n || y < 0 || y >= m) return 0;
if(x == n - 1 && y == m - 1) return 1;
if(v[x][y]) return 0;
if(bl[x][y]) return 0;
bl[x][y] = 1;
return dfs(x + 1, y) | dfs(x, y + 1);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
v = vector<vector<bool>>(n, vector<bool>(m));
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
bool bll; cin >> bll;
v[i][j] = bll;
}
int q; cin >> q;
while(q--){
bl = vector<vector<bool>>(n, vector<bool>(m, 0));
int x, y; cin >> x >> y;
x--, y--;
v[x][y] = 1;
if(dfs(0, 0)) cout << "1\n";
else{
v[x][y] = 0;
cout << "0\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
384 KB |
Output is correct |
2 |
Correct |
89 ms |
384 KB |
Output is correct |
3 |
Correct |
152 ms |
508 KB |
Output is correct |
4 |
Correct |
286 ms |
464 KB |
Output is correct |
5 |
Correct |
309 ms |
504 KB |
Output is correct |
6 |
Correct |
479 ms |
504 KB |
Output is correct |
7 |
Correct |
280 ms |
504 KB |
Output is correct |
8 |
Correct |
309 ms |
508 KB |
Output is correct |
9 |
Correct |
536 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
384 KB |
Output is correct |
2 |
Correct |
89 ms |
384 KB |
Output is correct |
3 |
Correct |
152 ms |
508 KB |
Output is correct |
4 |
Correct |
286 ms |
464 KB |
Output is correct |
5 |
Correct |
309 ms |
504 KB |
Output is correct |
6 |
Correct |
479 ms |
504 KB |
Output is correct |
7 |
Correct |
280 ms |
504 KB |
Output is correct |
8 |
Correct |
309 ms |
508 KB |
Output is correct |
9 |
Correct |
536 ms |
504 KB |
Output is correct |
10 |
Correct |
4640 ms |
1016 KB |
Output is correct |
11 |
Correct |
211 ms |
504 KB |
Output is correct |
12 |
Execution timed out |
5068 ms |
2936 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |