Submission #1091898

# Submission time Handle Problem Language Result Execution time Memory
1091898 2024-09-22T13:49:11 Z steveonalex Park (BOI16_park) C++17
0 / 100
230 ms 25284 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;
}

int calc_dis(pair<int, int> a, pair<int, int> b){
    return ceil(sqrt(sqr(a.first - b.first) + sqr(a.second - b.second)));
}
 
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<int, 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<int, 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){
        int r, e; cin >> r >> e;
        edge.push_back({{-i, e, r * 2}});
    }

    sort(ALL(edge), [](array<int, 3> x, array<int, 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 227 ms 25272 KB Output is correct
2 Correct 213 ms 25280 KB Output is correct
3 Correct 227 ms 25276 KB Output is correct
4 Correct 215 ms 25280 KB Output is correct
5 Correct 230 ms 25276 KB Output is correct
6 Correct 214 ms 25180 KB Output is correct
7 Correct 190 ms 25280 KB Output is correct
8 Incorrect 194 ms 25284 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 3536 KB Output is correct
2 Correct 31 ms 3524 KB Output is correct
3 Correct 31 ms 3532 KB Output is correct
4 Correct 31 ms 3524 KB Output is correct
5 Correct 35 ms 3472 KB Output is correct
6 Incorrect 32 ms 3608 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 227 ms 25272 KB Output is correct
2 Correct 213 ms 25280 KB Output is correct
3 Correct 227 ms 25276 KB Output is correct
4 Correct 215 ms 25280 KB Output is correct
5 Correct 230 ms 25276 KB Output is correct
6 Correct 214 ms 25180 KB Output is correct
7 Correct 190 ms 25280 KB Output is correct
8 Incorrect 194 ms 25284 KB Output isn't correct
9 Halted 0 ms 0 KB -