답안 #374452

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374452 2021-03-07T09:58:41 Z Mahdi_Shokoufi Park (BOI16_park) C++17
100 / 100
413 ms 37852 KB
//In the name of Allah
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define Sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()

const int N = 2010;
const int M = 1e5 + 10;

int x[N], y[N], r[N], par[N], sz[N], ans[M][5];
vector < pair < double , pair < int , int > > > vec, qry;

int getPar(int v){
    return par[v] == v ? v : par[v] = getPar(par[v]);
}

void merge(int u, int v){
    u = getPar(u); v = getPar(v);
    if (u == v)
        return;
    if (sz[v] < sz[u])
        swap(u, v);
    par[u] = v;
    sz[v] += sz[u];
}

bool c(int u, int v){
    return getPar(u) != getPar(v);
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q, w, h;
    cin >> n >> q >> w >> h;
    n += 4;
    for (int i = 5; i <= n; i ++)
        cin >> x[i] >> y[i] >> r[i];
    for (int i = 5; i <= n; i ++){
        vec.pb(mp(x[i] - r[i], mp(1, i)));
        vec.pb(mp(y[i] - r[i], mp(2, i)));
        vec.pb(mp(w - x[i] - r[i], mp(3, i)));
        vec.pb(mp(h - y[i] - r[i], mp(4, i)));
        for (int j = i + 1; j <= n; j ++)
            vec.pb(mp(sqrt(1LL * (x[i] - x[j]) * (x[i] - x[j]) + 1LL * (y[i] - y[j]) * (y[i] - y[j]) + 0.0) - r[i] - r[j], mp(i, j)));
    }
    for (int i = 0; i < q; i ++){
        int rd, p; cin >> rd >> p;
        qry.pb(mp(2 * rd, mp(p, i)));
    }
    sort(all(vec)); sort(all(qry));
    int ptr = 0;
    for (int i = 0; i < N; i ++)
        par[i] = i, sz[i] = 1;
    for (int i = 0; i < q; i ++){
        while (ptr < Sz(vec) && vec[ptr].X < qry[i].X)
            merge(vec[ptr].Y.X, vec[ptr].Y.Y), ptr ++;
        int p = qry[i].Y.X, id = qry[i].Y.Y;
        ans[id][p] = 1;
        if (p == 1){
            ans[id][2] = c(2, 1) && c(2, 3) && c(2, 4);
            ans[id][3] = c(1, 2) && c(1, 3) && c(2, 4) && c(3, 4);
            ans[id][4] = c(1, 2) && c(1, 3) && c(1, 4);
        }
        else if (p == 2){
            ans[id][1] = c(2, 1) && c(2, 3) && c(2, 4);
            ans[id][3] = c(3, 1) && c(3, 2) && c(3, 4);
            ans[id][4] = c(1, 3) && c(1, 4) && c(2, 3) && c(2, 4);
        }
        else if (p == 3){
            ans[id][1] = c(1, 2) && c(1, 3) && c(2, 4) && c(3, 4);
            ans[id][2] = c(3, 1) && c(3, 2) && c(3, 4);
            ans[id][4] = c(4, 1) && c(4, 2) && c(4, 3);
        }
        else{
            ans[id][1] = c(1, 2) && c(1, 3) && c(1, 4);
            ans[id][2] = c(1, 3) && c(1, 4) && c(2, 3) && c(2, 4);
            ans[id][3] = c(4, 1) && c(4, 2) && c(4, 3);
        }
    }
    for (int i = 0; i < q; i ++){
        for (int j = 1; j <= 4; j ++)
            if (ans[i][j])
                cout << j;
        cout << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 33484 KB Output is correct
2 Correct 345 ms 33340 KB Output is correct
3 Correct 333 ms 33364 KB Output is correct
4 Correct 364 ms 33356 KB Output is correct
5 Correct 326 ms 33340 KB Output is correct
6 Correct 326 ms 33340 KB Output is correct
7 Correct 306 ms 33356 KB Output is correct
8 Correct 296 ms 33356 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 4748 KB Output is correct
2 Correct 66 ms 4712 KB Output is correct
3 Correct 58 ms 4712 KB Output is correct
4 Correct 60 ms 4748 KB Output is correct
5 Correct 62 ms 4712 KB Output is correct
6 Correct 61 ms 4712 KB Output is correct
7 Correct 60 ms 4324 KB Output is correct
8 Correct 53 ms 4324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 33484 KB Output is correct
2 Correct 345 ms 33340 KB Output is correct
3 Correct 333 ms 33364 KB Output is correct
4 Correct 364 ms 33356 KB Output is correct
5 Correct 326 ms 33340 KB Output is correct
6 Correct 326 ms 33340 KB Output is correct
7 Correct 306 ms 33356 KB Output is correct
8 Correct 296 ms 33356 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 74 ms 4748 KB Output is correct
12 Correct 66 ms 4712 KB Output is correct
13 Correct 58 ms 4712 KB Output is correct
14 Correct 60 ms 4748 KB Output is correct
15 Correct 62 ms 4712 KB Output is correct
16 Correct 61 ms 4712 KB Output is correct
17 Correct 60 ms 4324 KB Output is correct
18 Correct 53 ms 4324 KB Output is correct
19 Correct 413 ms 37784 KB Output is correct
20 Correct 385 ms 37784 KB Output is correct
21 Correct 394 ms 37780 KB Output is correct
22 Correct 388 ms 37652 KB Output is correct
23 Correct 385 ms 37784 KB Output is correct
24 Correct 380 ms 37852 KB Output is correct