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][1 + MAX_N + 1];
int diag[1 + 2 * MAX_N];
int n, m;
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 (x == 1 || y == m || blocked[x - 1][y + 1]) {
go_stupid (x, y + 1);
go_stupid (x - 1, y);
}
if (x == n || y == 1 || 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);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
diag[i + j]++;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
int x;
cin >> x;
if (x)
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |