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 MAX_N = 1042;
int c[MAX_N][MAX_N];
int ans[MAX_N][MAX_N];
int sum[MAX_N * 2];
void add (queue < pair < int, int > >& q, int x, int y) {
if (ans[x][y] == 1) {
//cout << x << " " << y << endl;
ans[x][y] = 0;
sum[x + y]--;
q.push({x, y});
}
}
int change(int x, int y) {
if (ans[x][y] == 0) {
return 1;
}
if (sum[x + y] == 1) {
return 0;
}
queue < pair < int, int > > q;
add(q, x, y);
while (!q.empty()) {
x = q.front().first;
y = q.front().second;
q.pop();
if (ans[x - 1][y + 1] == 0) {
add(q, x - 1, y);
add(q, x, y + 1);
}
if (ans[x + 1][y - 1] == 0) {
add(q, x + 1, y);
add(q, x, y - 1);
}
}
return 1;
}
int main() {
//freopen("input.txt", "r", stdin);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
sum[i + j]++;
ans[i][j] = 1;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> c[i][j];
if (c[i][j]) {
change(i, j);
}
}
}
int q;
cin >> q;
while (q--) {
int i, j;
cin >> i >> j;
cout << change(i, j) << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |