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>
#define int long long
#define a second
#define b first
using namespace std;
const int N = 1e3 + 42, INF = 1e18 + 42;
bool pos[N][N][2];
int n, m, q, nb[2*N], pre[N][N][2];
int delta[] = {1, -1};
void flood(int i, int j, int id) {
if(i >= n || j >= m || i < 0 || j < 0 || !pos[i][j][id])
return;
pre[i][j][id]--;
if(pre[i][j][id] == 0) {
if(pos[i][j][0] && pos[i][j][1])
nb[i + j]--;
pos[i][j][id] = false;
flood(i + delta[id], j, id);
flood(i, j + delta[id], id);
}
}
bool furniture(int i, int j) {
if(pos[i][j][0] && pos[i][j][1] && nb[i + j] == 1)
return false;
pre[i][j][0] = 1;
pre[i][j][1] = 1;
flood(i, j, 0);
flood(i, j, 1);
return true;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++) {
nb[i + j]++;
if(i != 0) pre[i][j][0]++;
if(j != 0) pre[i][j][0]++;
if(i != n-1) pre[i][j][1]++;
if(j != m-1) pre[i][j][1]++;
pos[i][j][0] = pos[i][j][1] = true;
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++) {
int x; cin >> x;
if(x) furniture(i, j);
}
cin >> q;
for(int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
cout << furniture(x-1, y-1) << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |