#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 1005;
int n, m, q, r, c, a[MN][MN], reach1[MN], reach2[MN];
int32_t main() {
boost();
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
cin >> q;
while (q--) {
cin >> r >> c;
a[r][c] = 1;
int ok = 1;
for (int i = 1; i <= n; i++) {
reach1[i] = m + 1;
for (int j = m; j > 0; j--) {
if (a[i][j] && j >= reach1[i - 1] - 1) reach1[i] = j;
}
if (reach1[i] == 1) ok = 0;
}
if (reach1[n] <= m) ok = 0;
for (int j = 1; j <= m; j++) {
reach2[j] = n + 1;
for (int i = n; i > 0; i--) {
if (a[i][j] && i >= reach2[j - 1] - 1) reach2[j] = i;
}
if (reach2[j] == 1) ok = 0;
}
if (reach2[m] <= n) ok = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] && j >= reach1[i] && i >= reach2[j]) ok = 0;
}
}
a[r][c] = ok;
printf("%lld\n", ok);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
700 KB |
Output is correct |
2 |
Incorrect |
148 ms |
900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
700 KB |
Output is correct |
2 |
Incorrect |
148 ms |
900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |