답안 #529305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529305 2022-02-22T17:35:26 Z rainliofficial Park (BOI16_park) C++17
100 / 100
361 ms 53812 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define f first
// #define s second

struct circle{
    int x, y, r, id;
};

struct edge{
    int from, to;
    double l;
};
struct person{
    int s, r, id;
};
struct DSU{
    vector<int> size, parent;
    DSU(int n){
        size.resize(n, 1);
        parent.resize(n);
        for (int i=0; i<n; i++){
            parent[i] = i;
        }
    }
    int find(int a){
        if (parent[a] == a){
            return a;
        }
        return parent[a] = find(parent[a]);
    }
    void join(int a, int b){  
        a = find(a);
        b = find(b);
        if (a == b){
            // Same component
            return;
        }
        if (size[a] < size[b]){
            // Point a to b
            parent[a] = b;
            size[b] += size[a];
        }else{
            // Point b to a
            parent[b] = a;
            size[a] += size[b];
        }
    }
};

const int MAXN = 2000+5, MAXM = 1e5+5, L = 0, D = 1, R = 2, U = 3;
int n, m, w, h;
circle arr[MAXN];
person vis[MAXM];

double dist(int a, int b){
    if (a < 4 && b < 4){
        return -1;
    }
    if (a < 4){
        if (arr[a].x == -1){
            return abs(arr[a].y - arr[b].y) - arr[b].r;
        }else{
            return abs(arr[a].x - arr[b].x) - arr[b].r;
        }
    }else if (b < 4){
        if (arr[b].x == -1){
            return abs(arr[b].x -arr[a].y) - arr[a].r;
        }else{
            return abs(arr[b].y - arr[a].x) - arr[a].r;
        }
    }
    return sqrt((ll)(arr[a].x - arr[b].x)*(arr[a].x - arr[b].x) + (ll)(arr[a].y - arr[b].y)*(arr[a].y - arr[b].y)) - arr[a].r - arr[b].r;
}

int main(){
    cin.tie(0); ios_base::sync_with_stdio(0);
    // freopen("file.in", "r", stdin);
    // freopen("file2.out", "w", stdout);
    cin >> n >> m >> w >> h;
    n += 4;
    arr[0] = {0, -1, 0, 0};
    arr[1] = {-1, 0, 0, 1};
    arr[2] = {w, -1, 0, 2};
    arr[3] = {-1, h, 0, 3};
    for (int i=4; i<n; i++){
        int x, y, r;
        cin >> x >> y >> r;
        arr[i] = {x, y, r, i};
    }
    vector<edge> edges;
    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            if (i < 4 && j < 4){
                continue;
            }
            edges.push_back({i, j, dist(i, j)});
        }
    }
    sort(edges.begin(), edges.end(), [](const edge& a, const edge& b){
        return a.l < b.l;
    });
    // for (int i=0; i<sz(edges); i++){
    //     cout << edges[i].from << " " << edges[i].to << " " << edges[i].l << "\n";
    // }
    for (int i=0; i<m; i++){
        int x, r;
        cin >> r >> x;
        vis[i] = {x, r, i};
    }
    sort(vis, vis+m, [](const person& a, const person& b) {return a.r < b.r;});
    // for (int i=0; i<m; i++){
    //     cout << vis[i].f << " " << vis[i].s << "\n";
    // }
    int e = 0;
    vector<set<int>> output(m);
    DSU dsu(n);
    for (int i=0; i<m; i++){
        while (e < sz(edges) && edges[e].l < 2*vis[i].r){
            dsu.join(edges[e].from, edges[e].to);
            // cout << edges[e].from << " " << edges[e].to << "\n";
            e++;
        }
        set<int> ans;
        ans.insert(vis[i].s);
        if (dsu.find(U) != dsu.find(D)){
            if (vis[i].s == 1 && dsu.find(D) != dsu.find(R) && dsu.find(D) != dsu.find(L)){
                ans.insert(2);
            }else if (vis[i].s == 2 && dsu.find(D) != dsu.find(L) && dsu.find(D) != dsu.find(R)){
                ans.insert(1);
            }else if (vis[i].s == 3 && dsu.find(L) != dsu.find(U) && dsu.find(U) != dsu.find(R)){
                ans.insert(4);
            }else if (vis[i].s == 4 && dsu.find(U) != dsu.find(R) && dsu.find(U) != dsu.find(L)){
                ans.insert(3);
            }
        }
        if (dsu.find(L) != dsu.find(R)){
            if (vis[i].s == 1 && dsu.find(L) != dsu.find(U)&& dsu.find(D) != dsu.find(L)){
                ans.insert(4);
            }else if (vis[i].s == 2 && dsu.find(R) != dsu.find(U) && dsu.find(D) != dsu.find(R)){
                ans.insert(3);
            }else if (vis[i].s == 3 && dsu.find(D) != dsu.find(R)&& dsu.find(U) != dsu.find(R)){
                ans.insert(2);
            }else if (vis[i].s == 4 && dsu.find(D) != dsu.find(L) && dsu.find(U) != dsu.find(L)){
                ans.insert(1);
            }
        }
        if (dsu.find(U) != dsu.find(D) && dsu.find(L) != dsu.find(R)){
            if (vis[i].s == 1 && dsu.find(U) != dsu.find(R) && dsu.find(D) != dsu.find(L)){
                ans.insert(3);
            }else if (vis[i].s == 2 && dsu.find(L) != dsu.find(U) && dsu.find(D) != dsu.find(R)){
                ans.insert(4);
            }else if (vis[i].s == 3 && dsu.find(D) != dsu.find(L) && dsu.find(U) != dsu.find(R)){
                ans.insert(1);
            }else if (vis[i].s == 4 && dsu.find(D) != dsu.find(R) && dsu.find(U) != dsu.find(L)){
                ans.insert(2);
            }
        }
        output[vis[i].id] = ans;
        // cout << "\n";
    }
    for (int i=0; i<m; i++){
        for (int j : output[i]){
            cout << j;
        }
        cout << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 33212 KB Output is correct
2 Correct 252 ms 33328 KB Output is correct
3 Correct 251 ms 33312 KB Output is correct
4 Correct 257 ms 33432 KB Output is correct
5 Correct 252 ms 33328 KB Output is correct
6 Correct 253 ms 33336 KB Output is correct
7 Correct 239 ms 33328 KB Output is correct
8 Correct 227 ms 33320 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 19916 KB Output is correct
2 Correct 83 ms 19012 KB Output is correct
3 Correct 83 ms 18912 KB Output is correct
4 Correct 83 ms 19108 KB Output is correct
5 Correct 91 ms 19208 KB Output is correct
6 Correct 96 ms 21972 KB Output is correct
7 Correct 68 ms 17056 KB Output is correct
8 Correct 70 ms 16964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 33212 KB Output is correct
2 Correct 252 ms 33328 KB Output is correct
3 Correct 251 ms 33312 KB Output is correct
4 Correct 257 ms 33432 KB Output is correct
5 Correct 252 ms 33328 KB Output is correct
6 Correct 253 ms 33336 KB Output is correct
7 Correct 239 ms 33328 KB Output is correct
8 Correct 227 ms 33320 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 92 ms 19916 KB Output is correct
12 Correct 83 ms 19012 KB Output is correct
13 Correct 83 ms 18912 KB Output is correct
14 Correct 83 ms 19108 KB Output is correct
15 Correct 91 ms 19208 KB Output is correct
16 Correct 96 ms 21972 KB Output is correct
17 Correct 68 ms 17056 KB Output is correct
18 Correct 70 ms 16964 KB Output is correct
19 Correct 351 ms 52192 KB Output is correct
20 Correct 343 ms 50648 KB Output is correct
21 Correct 355 ms 53812 KB Output is correct
22 Correct 327 ms 48784 KB Output is correct
23 Correct 339 ms 50024 KB Output is correct
24 Correct 361 ms 53108 KB Output is correct