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;
const int nmax = 1e3 + 5;
int jd[nmax][nmax], ss[nmax][nmax], diag[nmax], n, m;
int f[nmax][nmax];
void remo(int i, int j) {
if (f[i][j]) return;
f[i][j] = 1, diag[i + j]--;
if (--jd[i+1][j] == 0) remo(i+1, j);
if (--jd[i][j+1] == 0) remo(i, j+1);
if (--ss[i-1][j] == 0) remo(i-1, j);
if (--ss[i][j-1] == 0) remo(i, j-1);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; f[i][0] = f[i][m+1] = 1, i++) {
for (int j = 1; j <= m; f[0][j] = f[n+1][j] = 1, j++) {
diag[i+j]++;
jd[i+1][j]++, jd[i][j+1]++;
ss[i-1][j]++, ss[i][j-1]++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int x; cin >> x;
if (x) remo(i, j);
}
}
int q; cin >> q;
while (q--) {
int i, j, ans = 0; cin >> i >> j;
if (diag[i + j] != 1 || f[i][j] == 1)
remo(i, j), ans = 1;
cout << ans << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |