This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<vector<bool>> good(n + 2, vector<bool>(m + 2));
vector<int> cnt(n + m + 1);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
good[i][j] = 1;
cnt[i + j]++;
}
}
auto put = [&](int X, int Y) {
if(!good[X][Y]) {
return 1;
}
if(cnt[X + Y] == 1) {
return 0;
}
function<void(int, int)> dfs = [&](int x, int y) {
auto maybe = [&](int tx, int ty) {
if(good[tx][ty]) {
good[tx][ty] = 0;
cnt[tx + ty]--;
dfs(tx, ty);
}
};
if(!good[x - 1][y + 1]) {
maybe(x - 1, y);
maybe(x, y + 1);
}
if(!good[x + 1][y - 1]) {
maybe(x, y - 1);
maybe(x + 1, y);
}
};
good[X][Y] = 0;
cnt[X + Y]--;
dfs(X, Y);
return 1;
};
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
int c;
cin >> c;
if(c == 1) {
put(i, j);
}
}
}
int q;
cin >> q;
for(int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
cout << put(x, y) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |