답안 #1053692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053692 2024-08-11T15:38:28 Z SzymonKrzywda Furniture (JOI20_furniture) C++17
0 / 100
5 ms 2396 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Incorrect 5 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Incorrect 5 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -