#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 |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
436 KB |
Output is correct |
3 |
Correct |
10 ms |
332 KB |
Output is correct |
4 |
Correct |
19 ms |
460 KB |
Output is correct |
5 |
Correct |
20 ms |
460 KB |
Output is correct |
6 |
Correct |
24 ms |
504 KB |
Output is correct |
7 |
Correct |
23 ms |
460 KB |
Output is correct |
8 |
Correct |
23 ms |
496 KB |
Output is correct |
9 |
Correct |
23 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
436 KB |
Output is correct |
3 |
Correct |
10 ms |
332 KB |
Output is correct |
4 |
Correct |
19 ms |
460 KB |
Output is correct |
5 |
Correct |
20 ms |
460 KB |
Output is correct |
6 |
Correct |
24 ms |
504 KB |
Output is correct |
7 |
Correct |
23 ms |
460 KB |
Output is correct |
8 |
Correct |
23 ms |
496 KB |
Output is correct |
9 |
Correct |
23 ms |
460 KB |
Output is correct |
10 |
Correct |
61 ms |
728 KB |
Output is correct |
11 |
Correct |
18 ms |
424 KB |
Output is correct |
12 |
Correct |
867 ms |
6032 KB |
Output is correct |
13 |
Correct |
201 ms |
3012 KB |
Output is correct |
14 |
Correct |
1976 ms |
10716 KB |
Output is correct |
15 |
Correct |
2112 ms |
10924 KB |
Output is correct |
16 |
Correct |
2170 ms |
11936 KB |
Output is correct |
17 |
Correct |
2278 ms |
12664 KB |
Output is correct |
18 |
Correct |
2207 ms |
12132 KB |
Output is correct |
19 |
Correct |
2348 ms |
12980 KB |
Output is correct |
20 |
Correct |
2426 ms |
12916 KB |
Output is correct |
21 |
Correct |
2333 ms |
12924 KB |
Output is correct |