// 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 |
1 |
Correct |
4 ms |
8504 KB |
Output is correct |
2 |
Correct |
5 ms |
8652 KB |
Output is correct |
3 |
Correct |
6 ms |
8620 KB |
Output is correct |
4 |
Correct |
7 ms |
8756 KB |
Output is correct |
5 |
Correct |
6 ms |
8776 KB |
Output is correct |
6 |
Correct |
7 ms |
8780 KB |
Output is correct |
7 |
Correct |
7 ms |
8780 KB |
Output is correct |
8 |
Correct |
6 ms |
8780 KB |
Output is correct |
9 |
Correct |
7 ms |
8780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8504 KB |
Output is correct |
2 |
Correct |
5 ms |
8652 KB |
Output is correct |
3 |
Correct |
6 ms |
8620 KB |
Output is correct |
4 |
Correct |
7 ms |
8756 KB |
Output is correct |
5 |
Correct |
6 ms |
8776 KB |
Output is correct |
6 |
Correct |
7 ms |
8780 KB |
Output is correct |
7 |
Correct |
7 ms |
8780 KB |
Output is correct |
8 |
Correct |
6 ms |
8780 KB |
Output is correct |
9 |
Correct |
7 ms |
8780 KB |
Output is correct |
10 |
Correct |
15 ms |
9004 KB |
Output is correct |
11 |
Correct |
6 ms |
8544 KB |
Output is correct |
12 |
Correct |
220 ms |
20716 KB |
Output is correct |
13 |
Correct |
116 ms |
17628 KB |
Output is correct |
14 |
Correct |
333 ms |
25176 KB |
Output is correct |
15 |
Correct |
335 ms |
25400 KB |
Output is correct |
16 |
Correct |
334 ms |
26456 KB |
Output is correct |
17 |
Correct |
353 ms |
27300 KB |
Output is correct |
18 |
Correct |
337 ms |
26932 KB |
Output is correct |
19 |
Correct |
381 ms |
27852 KB |
Output is correct |
20 |
Correct |
305 ms |
27720 KB |
Output is correct |
21 |
Correct |
345 ms |
27692 KB |
Output is correct |