# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
349015 | apostoldaniel854 | Furniture (JOI20_furniture) | C++14 | 0 ms | 0 KiB |
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>
using namespace std;
#define pb push_back
const int MAX_N = 1000;
bool blocked[1 + MAX_N][1 + MAX_N];
void go_stupid (int x, int y) {
if (x >= 1 && x <= n && y >= 1 && y <= m) {
if (not blocked[x][y]) {
blocked[x][y] = true;
diag[x + y]--;
if (blocked[x - 1][y + 1]) {
go_stupid (x, y + 1);
go_stupid (x - 1, y);
}
if (blocked[x + 1][y - 1]) {
go_stupid (x, y - 1);
go_stupid (x + 1, y);
}
}
}
}
int main() {
ios::sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
int x;
cin >> x;
if (x)
diag[i + j]++;
else
go_stupid (i, j);
}
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
if (blocked[x][y])
cout << "1\n";
else if (diag[x][y] == 1)
cout << "0\n";
else {
cout << "1\n";
go_stupid (x, y);
}
}
return 0;
}