#include <bits/stdc++.h>
using namespace std;
int przekatne[2010];
int tablica[2010][2010];
void rozlej(int a, int b){
stack<pair<int,int>> kolejka;
kolejka.push({a,b});
while (!kolejka.empty()){
int y = kolejka.top().first;
int x = kolejka.top().second;
kolejka.pop();
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});
}
}
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;
//cout << przekatne[a+b] << endl;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
5 ms |
2604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Incorrect |
5 ms |
2604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |