Submission #233960

# Submission time Handle Problem Language Result Execution time Memory
233960 2020-05-22T13:41:06 Z anhkha2003 Park (BOI16_park) C++14
100 / 100
699 ms 104020 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 {
    long long 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-2, 1-3, 1-4
    // 1 -> 3: 1-4, 1-3, 2-3, 2-4
    // 1 -> 4: 1-4, 2-4, 3-4
    // 2 -> 3: 1-2, 2-4, 2-3
    // 2 -> 4: 1-2, 3-4, 1-3, 2-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][3], green[1][4], 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][4], green[2][3]});
    ans[2][4] = ans[4][2] = min({green[1][2], green[1][3], green[3][4], green[2][4]});
    ans[3][4] = ans[4][3] = min({green[1][3], green[2][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;
}
# Verdict Execution time Memory Grader output
1 Correct 643 ms 102464 KB Output is correct
2 Correct 652 ms 102488 KB Output is correct
3 Correct 642 ms 102488 KB Output is correct
4 Correct 652 ms 102508 KB Output is correct
5 Correct 659 ms 102488 KB Output is correct
6 Correct 639 ms 102360 KB Output is correct
7 Correct 570 ms 102492 KB Output is correct
8 Correct 560 ms 102688 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 3192 KB Output is correct
2 Correct 49 ms 3180 KB Output is correct
3 Correct 50 ms 3696 KB Output is correct
4 Correct 49 ms 3696 KB Output is correct
5 Correct 52 ms 3692 KB Output is correct
6 Correct 51 ms 3696 KB Output is correct
7 Correct 44 ms 1916 KB Output is correct
8 Correct 43 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 643 ms 102464 KB Output is correct
2 Correct 652 ms 102488 KB Output is correct
3 Correct 642 ms 102488 KB Output is correct
4 Correct 652 ms 102508 KB Output is correct
5 Correct 659 ms 102488 KB Output is correct
6 Correct 639 ms 102360 KB Output is correct
7 Correct 570 ms 102492 KB Output is correct
8 Correct 560 ms 102688 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 53 ms 3192 KB Output is correct
12 Correct 49 ms 3180 KB Output is correct
13 Correct 50 ms 3696 KB Output is correct
14 Correct 49 ms 3696 KB Output is correct
15 Correct 52 ms 3692 KB Output is correct
16 Correct 51 ms 3696 KB Output is correct
17 Correct 44 ms 1916 KB Output is correct
18 Correct 43 ms 1912 KB Output is correct
19 Correct 678 ms 103776 KB Output is correct
20 Correct 679 ms 104020 KB Output is correct
21 Correct 691 ms 103768 KB Output is correct
22 Correct 685 ms 103704 KB Output is correct
23 Correct 699 ms 103768 KB Output is correct
24 Correct 612 ms 103912 KB Output is correct