#include <bits/stdc++.h>
using namespace std;
int in[1005][1005], out[1005][1005], a[1005][1005], cnt[2005];
void remove(int i, int j) {
if (a[i][j]) return;
a[i][j] = 1, cnt[i + j]--;
if (--in[i+1][j] == 0) remove(i+1, j);
if (--in[i][j+1] == 0) remove(i, j+1);
if (--out[i-1][j] == 0) remove(i-1, j);
if (--out[i][j-1] == 0) remove(i, j-1);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, m; cin >> n >> m;
for (int i = 1; i <= n; a[i][0] = a[i][m+1] = 1, i++) {
for (int j = 1; j <= m; a[0][j] = a[n+1][j] = 1, j++) {
cnt[i+j]++;
in[i+1][j]++, in[i][j+1]++;
out[i-1][j]++, out[i][j-1]++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int x; cin >> x;
if (x) remove(i, j);
}
}
int q; cin >> q;
while (q--) {
int i, j, ans = 0; cin >> i >> j;
if (cnt[i + j] != 1 || a[i][j] == 1)
remove(i, j), ans = 1;
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
2 ms |
1536 KB |
Output is correct |
3 |
Correct |
3 ms |
1536 KB |
Output is correct |
4 |
Correct |
4 ms |
1536 KB |
Output is correct |
5 |
Correct |
4 ms |
1664 KB |
Output is correct |
6 |
Correct |
4 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
1664 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
4 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1280 KB |
Output is correct |
2 |
Correct |
2 ms |
1536 KB |
Output is correct |
3 |
Correct |
3 ms |
1536 KB |
Output is correct |
4 |
Correct |
4 ms |
1536 KB |
Output is correct |
5 |
Correct |
4 ms |
1664 KB |
Output is correct |
6 |
Correct |
4 ms |
1664 KB |
Output is correct |
7 |
Correct |
4 ms |
1664 KB |
Output is correct |
8 |
Correct |
4 ms |
1664 KB |
Output is correct |
9 |
Correct |
4 ms |
1664 KB |
Output is correct |
10 |
Correct |
11 ms |
1408 KB |
Output is correct |
11 |
Correct |
3 ms |
1024 KB |
Output is correct |
12 |
Correct |
196 ms |
16780 KB |
Output is correct |
13 |
Correct |
79 ms |
13560 KB |
Output is correct |
14 |
Correct |
334 ms |
20964 KB |
Output is correct |
15 |
Correct |
369 ms |
21216 KB |
Output is correct |
16 |
Correct |
356 ms |
22392 KB |
Output is correct |
17 |
Correct |
379 ms |
23416 KB |
Output is correct |
18 |
Correct |
359 ms |
22904 KB |
Output is correct |
19 |
Correct |
396 ms |
23800 KB |
Output is correct |
20 |
Correct |
340 ms |
23836 KB |
Output is correct |
21 |
Correct |
392 ms |
23928 KB |
Output is correct |