이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I may fail a thousand times
// But there is no giving up
// IOI - here I come
#include <bits/stdc++.h>
#define int long long
using namespace std;
queue<int> q;
map<int,int> mp;
int v[(int)1e3+5][(int)1e3+5];
int a[(int)1e3+5][(int)1e3+5];
void push(int x,int y){
if(a[x][y])return;
q.push(x);q.push(y);
a[x][y]=1;
mp[x+y]--;
}
int upd(int x,int y){
if(a[x][y])return 1;
if(mp[x+y]==1)return 0;
mp[x+y]--;
a[x][y]=1;
q.push(x);
q.push(y);
for(;!q.empty();){
int nx=q.front();q.pop();
int ny=q.front();q.pop();
if(a[nx+1][ny-1])push(nx+1,ny),push(nx,ny-1);
if(a[nx-1][ny+1])push(nx-1,ny),push(nx,ny+1);
}
return 1;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
memset(a,1,sizeof a);
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
mp[i+j]++;
a[i][j]=0;
cin>>v[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(v[i][j]){
upd(i,j);
}
}
}
int q;cin>>q;
for(;q;q--){
int x,y;cin>>x>>y;
cout<<upd(x,y)<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |