#include<bits/stdc++.h>
using namespace std;
int n,m,c,x,y,q;
bool blocked[1007][1007];
int good[2007];
void checkup(int a,int b);
void checkdown(int a,int b);
bool add(int a,int b){
if(blocked[a][b])
return 1;
if(good[a+b]==1)
return 0;
blocked[a][b]=1;
good[a+b]--;
checkup(a-1,b);
checkup(a,b-1);
checkdown(a+1,b);
checkdown(a,b+1);
return 1;
}
void checkup(int a,int b){
if(!(blocked[a+1][b] && blocked[a][b+1]))
return;
if(blocked[a][b])
return;
blocked[a][b]=1;
good[a+b]--;
checkup(a-1,b);
checkup(a,b-1);
}
void checkdown(int a,int b){
//cout<<a<<" "<<b<<" ";
if(!(blocked[a-1][b] && blocked[a][b-1]))
return;
if(blocked[a][b])
return;
blocked[a][b]=1;
good[a+b]--;
checkdown(a+1,b);
checkdown(a,b+1);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m;
for(int i=0;i<=n+1;i++){
blocked[i][0]=1;
blocked[i][m+1]=1;
}
for(int i=0;i<=m;i++){
blocked[0][i]=1;
blocked[n+1][i]=1;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
good[j+i+2]++;
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>c;
if(c)
add(i+1,j+1);
//cout<<"Error";
/*for(int k=0;k<n;k++){
for(int l=0;l<m;l++){
cout<<blocked[k+1][l+1]<<" ";
}
cout<<"\n";
}
cout<<"\n";*/
}
}
cin>>q;
for(int i=0;i<q;i++){
cin>>x>>y;
cout<<add(x,y)<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
592 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
800 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
65 ms |
2008 KB |
Output is correct |
13 |
Correct |
28 ms |
1368 KB |
Output is correct |
14 |
Correct |
120 ms |
2896 KB |
Output is correct |
15 |
Correct |
123 ms |
2896 KB |
Output is correct |
16 |
Correct |
134 ms |
3156 KB |
Output is correct |
17 |
Correct |
135 ms |
3240 KB |
Output is correct |
18 |
Correct |
143 ms |
3156 KB |
Output is correct |
19 |
Correct |
137 ms |
3412 KB |
Output is correct |
20 |
Correct |
152 ms |
3604 KB |
Output is correct |
21 |
Correct |
150 ms |
3408 KB |
Output is correct |