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;
int n, m;
const int MXN = 1005;
int grid[MXN][MXN];
void place(int a, int b) {
if (grid[a][b] == 0) return;
grid[a][b] = 0;
{
if (grid[a-1][b+1] == 0) {
place(a, b+1);
place(a-1, b);
}
}
{
if (grid[a+1][b-1] == 0) {
place(a+1, b);
place(a, b-1);
}
}
}
int oper(int x, int y) {
if (grid[x][y] == 0) {
place(x, y);
return 1;
}
int tr = 0;
for (int on=1; on<=n; on++) {
int ot = x + y - on;
if (1 <= ot && ot <= m) {
if (grid[on][ot]) tr++;
}
}
if (tr > 1) {
place(x, y);
return 1;
}
else {
return 0;
}
}
signed main() {
cin >> n >> m;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
grid[i][j] = 1;
}
}
int x;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin >> x;
if (x == 1) {
oper(i, j);
}
}
}
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
cout << oper(x, y) << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |