이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
bool blocked_s[N][N], blocked_t[N][N];
int unblocked[2 * N], n, m;
void block_s(int x, int y) {
unblocked[x + y] -= !blocked_t[x][y];
blocked_s[x][y] = true;
if (x < n - 1 && !blocked_s[x + 1][y] && (y == 0 || blocked_s[x + 1][y - 1])) {
block_s(x + 1, y);
}
if (y < m - 1 && !blocked_s[x][y + 1] && (x == 0 || blocked_s[x - 1][y + 1])) {
block_s(x, y + 1);
}
}
void block_t(int x, int y) {
unblocked[x + y] -= !blocked_s[x][y];
blocked_t[x][y] = true;
if (x > 0 && !blocked_t[x - 1][y] && (y == m - 1 || blocked_t[x - 1][y + 1])) {
block_t(x - 1, y);
}
if (y > 0 && !blocked_t[x][y - 1] && (x == n - 1 || blocked_t[x + 1][y - 1])) {
block_t(x, y - 1);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int c;
cin >> c;
if (c == 1) {
if (!blocked_s[i][j]) {
block_s(i, j);
}
if (!blocked_t[i][j]) {
block_t(i, j);
}
}
++unblocked[i + j];
}
}
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
--x, --y;
if (blocked_s[x][y] || blocked_t[x][y]) {
cout << 1 << "\n";
} else if (unblocked[x + y] > 1) {
cout << 1 << "\n";
block_s(x, y);
block_t(x, y);
} else {
cout << 0 << "\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |