#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define N 1001
typedef long long ll;
using namespace std;
bool r[N][N];
int c[N][N];
int a[N*2];
vector<pair<int,int> >v;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin >> n >> m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> c[i][j];
if(c[i][j]==1) v.pb({i,j});
a[i+j]++;
}
}
for(pair<int,int>fur:v){
r[fur.ff][fur.ss]=1;
a[fur.ff+fur.ss]--;
if(r[fur.ff+1][fur.ss-1]==1){
if(r[fur.ff][fur.ss-1]==0){
r[fur.ff][fur.ss-1]=1;
a[fur.ff+fur.ss-1]--;
}
if(r[fur.ff+1][fur.ss]==0){
r[fur.ff+1][fur.ss]=1;
a[fur.ff+fur.ss+1]--;
}
}
if(r[fur.ff-1][fur.ss+1]==1){
if(r[fur.ff-1][fur.ss]==0){
r[fur.ff-1][fur.ss]=1;
a[fur.ff+fur.ss-1]--;
}
if(r[fur.ff][fur.ss+1]==0){
r[fur.ff][fur.ss+1]=1;
a[fur.ff+fur.ss+1]--;
}
}
}
int q;
cin >> q;
while(q--){
int x,y;
cin >> x >> y;
if(r[x][y]==1){
cout << 1 << '\n';
}
else{
if(a[x+y]>1){
cout << 1 << '\n';
r[x][y]=0;
a[x+y]--;
if(r[x+1][y-1]==1){
if(r[x][y-1]==0){
r[x][y-1]=1;
a[x+y-1]--;
}
if(r[x+1][y]==0){
r[x+1][y]=1;
a[x+y+1]--;
}
}
if(r[x-1][y+1]==1){
if(r[x-1][y]==0){
r[x-1][y]=1;
a[x+y-1]--;
}
if(r[x][y+1]==0){
r[x][y+1]=1;
a[x+y+1]--;
}
}
}
else cout << 0 << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Incorrect |
2 ms |
876 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Incorrect |
2 ms |
876 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |