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;
const int N = 1005;
int n, m;
bool SePoate[N][N];
int diag[N + N];
int b = 1;
struct ura{
int x, y;
};
int verif(int x, int y)
{
if (x < 1 || y < 1 || n < x || m < y)
return 1;
return 0;
}
void upd(int x, int y)
{
if (verif(x, y) || SePoate[x][y] == false)
return;
SePoate[x][y] = false;
diag[x + y]--;
if (verif(x - 1, y + 1) || SePoate[x - 1][y + 1] == false)
{
upd(x, y + 1);
upd(x - 1, y);
}
if (verif(x + 1, y - 1) || SePoate[x + 1][y - 1] == false)
{
upd(x, y - 1);
upd(x + 1, y);
}
}
int main()
{
int i, j;
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
SePoate[i][j] = true;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
{
int nr;
cin >> nr;
diag[i + j]++;
if (nr)
upd(i, j);
}
int q;
cin >> q;
while(q--)
{
int x, y;
cin >> x >> y;
if (SePoate[x][y] == false)
{
cout << 1 << '\n';
continue;
}
if (diag[x + y] > 1)
{
cout << 1 << '\n';
upd(x, y);
continue;
}
cout << 0 << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |