#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
bool avail[1005][1005][4];
bool C[1005][1005];
int maxn = 1005;
void block(int x, int y)
{
//cout<<"Blocking "<<x<<" "<<y<<endl;
if(C[x][y] == 1)
return;
C[x][y] = 1;
avail[x][y+1][0] = 0;
avail[x][y-1][2] = 0;
avail[x+1][y][1] = 0;
avail[x-1][y][3] = 0;
if(avail[x][y][2])
{
if(!avail[x][y+1][1])
block(x, y+1);
}
if(avail[x][y][3])
{
if(!avail[x+1][y][0])
block(x+1, y);
}
if(avail[x][y][0])
{
if(!avail[x][y-1][3])
block(x,y-1);
}
if(avail[x][y][1])
{
if(!avail[x-1][y][2])
block(x-1, y);
}
}
int main()
{
int n, m, q;
cin>>n>>m;
for(int i = 0; i<maxn; i++)
{
for(int j = 0; j<maxn; j++)
{
for(int dir = 0; dir<4; dir++)
{
avail[i][j][dir] = 0;
}
C[i][j] = 1;
}
}
for(int i = 1; i<=n; i++)
{
for(int j = 1; j<=m; j++)
{
if(i!=1)
avail[i][j][1]=1;
if(i!=n)
avail[i][j][3]=1;
if(j!=1)
avail[i][j][0]=1;
if(j!=m)
avail[i][j][2]=1;
C[i][j] = 0;
}
}
int t;
for(int i = 1; i<=n; i++)
{
for(int j = 1; j<=m; j++)
{
cin>>t;
if(t)
block(i,j);
}
}
/*
for(int i = 0; i<10; i++)
{
for(int j = 0; j<10; j++)
{
cout<<C[i][j]<<" ";
}
cout<<endl;
}
*/
cin>>q;
int x, y, js, ct;
while(q--)
{
cin>>x>>y;
if(C[x][y] == 1)
{
cout<<1<<endl;
continue;
}
ct = 0;
for(int i = 1; i<=n; i++)
{
js = x+y-i;
if(js < 1 || js > m)
continue;
if(C[i][js]==0)
ct++;
}
if(ct>1)
{
cout<<1<<endl;
block(x,y);
}
else
{
cout<<0<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5196 KB |
Output is correct |
2 |
Correct |
12 ms |
5196 KB |
Output is correct |
3 |
Correct |
14 ms |
5176 KB |
Output is correct |
4 |
Correct |
23 ms |
5308 KB |
Output is correct |
5 |
Correct |
29 ms |
5324 KB |
Output is correct |
6 |
Correct |
29 ms |
5344 KB |
Output is correct |
7 |
Correct |
27 ms |
5328 KB |
Output is correct |
8 |
Correct |
28 ms |
5324 KB |
Output is correct |
9 |
Correct |
30 ms |
5324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5196 KB |
Output is correct |
2 |
Correct |
12 ms |
5196 KB |
Output is correct |
3 |
Correct |
14 ms |
5176 KB |
Output is correct |
4 |
Correct |
23 ms |
5308 KB |
Output is correct |
5 |
Correct |
29 ms |
5324 KB |
Output is correct |
6 |
Correct |
29 ms |
5344 KB |
Output is correct |
7 |
Correct |
27 ms |
5328 KB |
Output is correct |
8 |
Correct |
28 ms |
5324 KB |
Output is correct |
9 |
Correct |
30 ms |
5324 KB |
Output is correct |
10 |
Correct |
72 ms |
5552 KB |
Output is correct |
11 |
Correct |
18 ms |
5196 KB |
Output is correct |
12 |
Correct |
1040 ms |
9796 KB |
Output is correct |
13 |
Correct |
233 ms |
7056 KB |
Output is correct |
14 |
Correct |
2246 ms |
14748 KB |
Output is correct |
15 |
Correct |
2344 ms |
15012 KB |
Output is correct |
16 |
Correct |
2294 ms |
15820 KB |
Output is correct |
17 |
Correct |
2276 ms |
16376 KB |
Output is correct |
18 |
Correct |
2498 ms |
16040 KB |
Output is correct |
19 |
Correct |
2497 ms |
16888 KB |
Output is correct |
20 |
Correct |
2381 ms |
16900 KB |
Output is correct |
21 |
Correct |
2494 ms |
16832 KB |
Output is correct |