이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |