답안 #233984

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233984 2020-05-22T15:20:51 Z anhkha2003 Park (BOI16_park) C++14
100 / 100
703 ms 103912 KB
#include <bits/stdc++.h>
using namespace std;

const long double EPS = 1e-8;

struct Circle{
    long long x, y, r;
};

long double sq(long double a) {
    return a * a;
}

long double distCircle(Circle a, Circle b) {
    long double dist = sq(a.x - b.x) + sq(a.y - b.y);
    dist = sqrt(dist) - a.r - b.r;
    return dist;
}

long long w, h;
long double distEdge(Circle a, int k) {
    if (k == 1) return a.y - a.r;
    if (k == 2) return w - a.x - a.r;
    if (k == 3) return h - a.y - a.r;
    return a.x - a.r;
}

struct Edge{
    int u, v;
    long double w;
};

bool cmp(const Edge &a, const Edge &b) {
    return a.w < b.w;
}

int root[2005];
int findRoot(int u) {
    while (root[u] >= 0) {
        u = root[u];
    }
    return u;
}

void join(int x, int y) {
    if (root[x] > root[y]) {
        swap(x, y);
    }
    root[x] += root[y];
    root[y] = x;
}

Circle circle[2005];
long double cost[2005][2005];
long double green[5][5];
long double ans[5][5];

int main() {
    //freopen("PARK.INP", "r", stdin);
    //freopen("PARK.OUT", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m >> w >> h;

    for (int i = 1; i <= n; i++) {
        cin >> circle[i].x >> circle[i].y >> circle[i].r;
    }

    vector<Edge> edges;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            cost[i][j] = distCircle(circle[i], circle[j]);
            edges.push_back({i, j, cost[i][j]});
        }

        for (int j = 1; j <= 4; j++) {
            cost[i][n + j] = distEdge(circle[i], j);
            edges.push_back({i, n + j, cost[i][n + j]});
        }
    }

    sort(edges.begin(), edges.end(), cmp);

    for (int i = 1; i <= n + 4; i++) {
        root[i] = -1;
    }
    for (int i = 1; i <= 4; i++) {
        for (int j = i + 1; j <= 4; j++) {
            green[i][j] = -1;
        }
    }

    for (auto &e: edges) {
        int x = findRoot(e.u);
        int y = findRoot(e.v);
        if (x == y) continue;

        join(x, y);

        for (int i = 1; i <= 4; i++) {
            for (int j = i + 1; j <= 4; j++) {
                if (findRoot(n + i) == findRoot(n + j) && green[i][j] == -1) {
                    green[i][j] = e.w;
                }
            }
        }
    }

    // 1 -> 2: 1-4, 1-3, 1-2
    // 1 -> 3: 1-4, 1-3, 2-4, 2-3
    // 1 -> 4: 1-4, 2-4, 3-4
    // 2 -> 3: 1-2, 2-4, 2-3
    // 2 -> 4: 1-2, 1-3, 2-4, 3-4
    // 3 -> 4: 2-3, 1-3, 3-4

    ans[1][2] = ans[2][1] = min({green[1][2], green[1][3], green[1][4]});
    ans[1][3] = ans[3][1] = min({green[1][4], green[1][3], green[2][3], green[2][4]});
    ans[1][4] = ans[4][1] = min({green[1][4], green[2][4], green[3][4]});
    ans[2][3] = ans[3][2] = min({green[1][2], green[2][3], green[2][4]});
    ans[2][4] = ans[4][2] = min({green[1][2], green[1][3], green[2][4], green[3][4]});
    ans[3][4] = ans[4][3] = min({green[2][3], green[1][3], green[3][4]});

    for (int i = 1; i <= m; i++) {
        int r, e;
        cin >> r >> e;

        for (int j = 1; j <= 4; j++) {
            if (e == j) ans[e][j] = 2e9;
            if (2 * r <= ans[e][j] + EPS) {
                cout << j;
            }
        }
        cout << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 646 ms 102368 KB Output is correct
2 Correct 656 ms 102356 KB Output is correct
3 Correct 643 ms 102360 KB Output is correct
4 Correct 647 ms 102488 KB Output is correct
5 Correct 660 ms 102440 KB Output is correct
6 Correct 645 ms 102616 KB Output is correct
7 Correct 582 ms 102488 KB Output is correct
8 Correct 575 ms 102488 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 3696 KB Output is correct
2 Correct 51 ms 3696 KB Output is correct
3 Correct 50 ms 3572 KB Output is correct
4 Correct 49 ms 3692 KB Output is correct
5 Correct 51 ms 3696 KB Output is correct
6 Correct 50 ms 3696 KB Output is correct
7 Correct 44 ms 1912 KB Output is correct
8 Correct 46 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 646 ms 102368 KB Output is correct
2 Correct 656 ms 102356 KB Output is correct
3 Correct 643 ms 102360 KB Output is correct
4 Correct 647 ms 102488 KB Output is correct
5 Correct 660 ms 102440 KB Output is correct
6 Correct 645 ms 102616 KB Output is correct
7 Correct 582 ms 102488 KB Output is correct
8 Correct 575 ms 102488 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 55 ms 3696 KB Output is correct
12 Correct 51 ms 3696 KB Output is correct
13 Correct 50 ms 3572 KB Output is correct
14 Correct 49 ms 3692 KB Output is correct
15 Correct 51 ms 3696 KB Output is correct
16 Correct 50 ms 3696 KB Output is correct
17 Correct 44 ms 1912 KB Output is correct
18 Correct 46 ms 1912 KB Output is correct
19 Correct 688 ms 103832 KB Output is correct
20 Correct 684 ms 103800 KB Output is correct
21 Correct 679 ms 103912 KB Output is correct
22 Correct 679 ms 103640 KB Output is correct
23 Correct 703 ms 103768 KB Output is correct
24 Correct 609 ms 103892 KB Output is correct