Submission #1091903

# Submission time Handle Problem Language Result Execution time Memory
1091903 2024-09-22T13:57:01 Z steveonalex Park (BOI16_park) C++17
100 / 100
636 ms 100176 KB
#include <bits/stdc++.h>
// #include "bubblesort2.h"
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
    double cur = rngesus(0, MASK(60) - 1);
    cur /= MASK(60) - 1;
    return l + cur * (r - l);
}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

struct DSU{
    int n;
    vector<int> parent, sz;

    DSU(int _n){
        n = _n;
        parent.resize(n); sz.resize(n, 1);
        for(int i = 1; i<n; ++i) parent[i] = i;
    }

    int find_set(int u){return (u == parent[u]) ? u : (parent[u] = find_set(parent[u]));}
    bool same_set(int u, int v){return find_set(u) == find_set(v);}

    bool join_set(int u, int v){
        u = find_set(u), v = find_set(v);
        if (u != v){
            if (sz[u] < sz[v]) swap(u, v);
            parent[v] = u;
            sz[u] += sz[v];
            return true;
        }
        return false;
    }

    int get_size(int u){return sz[find_set(u)];}
};

ll sqr(ll a){
    return a * a;
}

ll calc_dis(pair<int, int> a, pair<int, int> b){
    ll cur = sqr(a.first - b.first) + sqr(a.second - b.second);
    ll l = 0, r = 2e9;
    while(l < r){
        ll mid = (l + r + 1) >> 1;
        if (sqr(mid) <= cur) l = mid;
        else r = mid - 1;
    }
    return l;
}
 
int main(void){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m; cin >> n >> m;
    int w, h; cin >> w >> h;
    vector<array<ll, 3>> a(n);
    for(int i = 0; i<n; ++i) 
    for(int j = 0; j<3; ++j)
        cin >> a[i][j];

    int bottom = n, top = n + 1, left = n + 2, right = n + 3;
    int state[4][4]; memset(state, 0, sizeof state);
    int full_mask = MASK(4) - 1;
    state[0][1] = 9;
    state[0][2] = 1;
    state[0][3] = 2;
    state[1][2] = 8;
    state[1][3] = 4;
    state[2][3] = 3;

    vector<array<ll, 3>> edge;
    for(int i = 0; i<n; ++i){
        edge.push_back({{i, bottom, a[i][1] - a[i][2]}});
        edge.push_back({{i, top, h - a[i][1] - a[i][2]}});
        edge.push_back({{i, left, a[i][0] - a[i][2]}});
        edge.push_back({{i, right, w - a[i][0] - a[i][2]}});

        for(int j = i + 1; j < n; ++j){
            int dis = calc_dis(make_pair(a[i][0], a[i][1]), make_pair(a[j][0], a[j][1]));
            edge.push_back({{i, j, dis - a[i][2] - a[j][2]}});
        }
    }

    for(int i = 1; i<=m; ++i){
        ll r, e; cin >> r >> e;
        edge.push_back({{-i, e, r * 2}});
    }

    sort(ALL(edge), [](array<ll, 3> x, array<ll, 3> y){
        if (x[2] != y[2]) return x[2] < y[2];
        return x[0] < y[0];
    });

    vector<int> ans(m + 1);
    DSU mst(n + 4);

    for(auto i: edge){
        if (i[0] < 0){
            int e = i[1] - 1;
            int idx = -i[0];
            ans[idx] = full_mask;

            for(int x = 0; x < 4; ++x) for(int y = x + 1; y < 4; ++y) if (mst.same_set(n + x, n + y)){
                int cur = state[x][y];
                if (!GETBIT(cur, e)) cur = full_mask - cur;
                ans[idx] &= cur;
            }
        }
        else{
            mst.join_set(i[0], i[1]);
        }
    }
    for(int i = 1; i<=m; ++i){
        for(int j = 0; j< 4; ++j) if (GETBIT(ans[i], j))
            cout << j+1;
        cout << "\n";
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 567 ms 49688 KB Output is correct
2 Correct 539 ms 49796 KB Output is correct
3 Correct 561 ms 49796 KB Output is correct
4 Correct 553 ms 49796 KB Output is correct
5 Correct 548 ms 49800 KB Output is correct
6 Correct 542 ms 49876 KB Output is correct
7 Correct 492 ms 49988 KB Output is correct
8 Correct 490 ms 49804 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4028 KB Output is correct
2 Correct 36 ms 4032 KB Output is correct
3 Correct 46 ms 3860 KB Output is correct
4 Correct 37 ms 3952 KB Output is correct
5 Correct 38 ms 3784 KB Output is correct
6 Correct 36 ms 4048 KB Output is correct
7 Correct 31 ms 4632 KB Output is correct
8 Correct 32 ms 4560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 567 ms 49688 KB Output is correct
2 Correct 539 ms 49796 KB Output is correct
3 Correct 561 ms 49796 KB Output is correct
4 Correct 553 ms 49796 KB Output is correct
5 Correct 548 ms 49800 KB Output is correct
6 Correct 542 ms 49876 KB Output is correct
7 Correct 492 ms 49988 KB Output is correct
8 Correct 490 ms 49804 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 40 ms 4028 KB Output is correct
12 Correct 36 ms 4032 KB Output is correct
13 Correct 46 ms 3860 KB Output is correct
14 Correct 37 ms 3952 KB Output is correct
15 Correct 38 ms 3784 KB Output is correct
16 Correct 36 ms 4048 KB Output is correct
17 Correct 31 ms 4632 KB Output is correct
18 Correct 32 ms 4560 KB Output is correct
19 Correct 636 ms 100008 KB Output is correct
20 Correct 605 ms 99924 KB Output is correct
21 Correct 602 ms 100068 KB Output is correct
22 Correct 600 ms 99924 KB Output is correct
23 Correct 602 ms 99920 KB Output is correct
24 Correct 552 ms 100176 KB Output is correct