#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<int>> c(n, vector<int> (m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> c[i][j];
}
}
vector<int> dx = {0, 1}, dy = {1, 0};
function<bool(int, int)> dfs = [&](int x, int y) {
if (x == n - 1 && y == m - 1) {
return true;
}
for (int z = 0; z < 2; ++z) {
int nx = x + dx[z], ny = y + dy[z];
if (nx < 0 || nx >= n || ny < 0 || ny >= m || c[nx][ny]) continue;
return dfs(nx, ny);
}
return false;
};
auto check = [&](int x, int y) {
c[x][y] = 1;
if (dfs(0, 0)) {
return true;
}
c[x][y] = 0;
return false;
};
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
--x, --y;
cout << check(x, y) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |