이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |