답안 #1114482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114482 2024-11-19T03:12:52 Z ReLice Furniture (JOI20_furniture) C++17
0 / 100
2 ms 2640 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sz size()
#define bc back()
#define ins insert
#define fr first
#define sc second
#define ar array
#define endl "\n"
#define all(x) x.begin(), x.end()

using namespace std;

void start(){
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
}

const ll N = 1e3 + 7;
const ll mod = 1e9 + 7;

ll a[N][N];
ll cnt[N];

signed main(){
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    start();

    ll n, m;
    ll i, j;

    cin>>n>>m;

    vector<pair<ll,ll>> v;

    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            cin>>a[i][j];

            cnt[i + j] ++;

            if(a[i][j] == 1) {
                v.pb({i, j});
            }

            a[i][j] = 0;
        }
    }

    ll dir[6][2] = {
        {-1, 1},
        {-1, 0},
        {0, 1},
        {1, -1},
        {1, 0},
        {0, -1},
    };

    auto del = [&] (ll i, ll j){
        queue<ar<ll, 2>> q;
        q.push({i, j});
        a[i][j] = 1;
        cnt[i + j] --;

        auto ok = [&](ll x, ll y){return (x >= 1 && x <= n && y >= 1 && y <= m);};

        while(q.size()){
            auto cur = q.front();
            q.pop();

            for(ll k=0;k<6;k+=3){
                ll x = cur[0] + dir[k][0], y = cur[1] + dir[k][1];

                if(!ok(x, y) || a[x][y]){
                    for(auto d : {k + 1, k + 2}){
                        ll i = cur[0] + dir[d][0], j = cur[1] + dir[d][1];

                        if(ok(i, j) && !a[i][j]){
                            a[i][j] = 1;
                            cnt[i + j] --;
                            q.push({i, j});
                        }
                    }
                }
            }
        }
    };

    for(auto i : v){
        del(i.fr, i.sc);
    }

    ll q;
    cin>>q;

    while(q--){
        ll x, y;

        cin>>x>>y;

        if(a[x][y])cout<<1<<'\n';

        else if(cnt[x + y] == 1) cout<<0<<'\n';

        else {
            del(x, y);
            cout<<1<<'\n';
        }
    }
}
/*
2 1 0
10
1

*/

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Incorrect 2 ms 2640 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2640 KB Output is correct
2 Incorrect 2 ms 2640 KB Output isn't correct
3 Halted 0 ms 0 KB -