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;
int przekatne[2010];
int tablica[2010][2010];
void rozlej(int a, int b){
queue<pair<int,int>> kolejka;
kolejka.push({a,b});
while (!kolejka.empty()){
int y = kolejka.front().first;
int x = kolejka.front().second;
kolejka.pop();
//cout << y << " " << x << endl;
if (tablica[y+1][x-1]==1){
//cout << y+1 << " " << x-1 << " " << tablica[y+1][x-1] << endl;
if (tablica[y][x-1]==0){
przekatne[y+x-1]--;
tablica[y][x-1]=1;
kolejka.push({y,x-1});
}
if (tablica[y+1][x]==0){
przekatne[y+1+x]--;
tablica[y+1][x]=1;
kolejka.push({y+1,x});
}
}
if (tablica[y-1][x+1]==1){
if (tablica[y][x+1]==0){
przekatne[y+x+1]--;
tablica[y][x+1]=1;
kolejka.push({y,x+1});
}
if (tablica[y-1][x]==0){
przekatne[y-1+x]--;
tablica[y-1][x]=1;
kolejka.push({y-1,x});
}
}
}
}
int main(){
int n,m,q,a,b;
cin >> n >> m;
for (int i=0; i<n+2; i++){
for (int j=0; j<m+2; j++){
tablica[i][j] = 1;
}
}
for (int y=1; y<=n; y++){
for (int x=1; x<=m; x++){
cin >> tablica[y][x];
if (!tablica[y][x]) przekatne[y+x]++;
}
}
for (int y=1; y<=n; y++){
for (int x=1; x<=m; x++){
if (tablica[y][x]) rozlej(y,x);
}
}
cin >> q;
for (int k=0; k<q; k++){
cin >> a >> b;
if (przekatne[a+b]>1) {
przekatne[a+b]--;
tablica[a][b]=1;
rozlej(a,b);
cout << 1 << endl;
}
else cout << tablica[a][b] << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |