This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1005)
ll N,M;
ll cnt[2 * MAXN];
bool R[MAXN][MAXN];
void del(ll i, ll j){
if(R[i][j] == 1 || cnt[i + j] == 1) return;
cnt[i + j]--;
R[i][j] = 1;
if(i + 1 < N && (j == 0 || R[i + 1][j - 1] == 1)) del(i + 1,j);
if(i - 1 >= 0 && (j == M - 1 || R[i - 1][j + 1] == 1)) del(i - 1,j);
if(j + 1 < M && (i == 0 || R[i - 1][j + 1] == 1)) del(i,j + 1);
if(j - 1 >= 0 && (i == M - 1 || R[i + 1][j - 1] == 1)) del(i,j - 1);
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>N>>M;
for(ll i = 0;i < N;i++){
for(ll j = 0;j < M;j++){
cin>>R[i][j];
cnt[i + j]++;
if(R[i][j] == 1){
del(i,j);
}
}
}
ll Q;
cin>>Q;
for(ll i = 0;i < Q;i++){
ll A,B;
cin>>A>>B;
A--, B--;
del(A,B);
if(R[A][B]){
cout<<0<<'\n';
}else{
cout<<1<<'\n';
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |