Submission #164410

# Submission time Handle Problem Language Result Execution time Memory
164410 2019-11-20T13:13:11 Z dolphingarlic Park (BOI16_park) C++14
100 / 100
765 ms 54708 KB
#include <bits/stdc++.h>
#define FOR(i, x, y) for (ll i = x; i < y; i++)
#define x first
#define y second
typedef long long ll;
using namespace std;

ll cmp[2004];
ll find(ll a) {
    while (cmp[a] != a) cmp[a] = cmp[cmp[a]], a = cmp[a];
    return a;
}
void onion(ll a, ll b) { cmp[find(a)] = cmp[find(b)]; }

pair<pair<ll, ll>, ll> tree[2000], visitors[100000];
priority_queue<pair<double, pair<ll, ll>>> pq;
string ans[100000];

ll dist(pair<ll, ll> a, pair<ll, ll> b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, m, w, h;
    cin >> n >> m >> w >> h;
    FOR(i, 0, n + 4) cmp[i] = i;
    FOR(i, 0, n) {
        cin >> tree[i].x.x >> tree[i].x.y >> tree[i].y;
        FOR(j, 0, i) {
            pq.push({-(sqrt(dist(tree[i].x, tree[j].x)) - tree[i].y - tree[j].y), {i, j}});
        }
        pq.push({-(tree[i].x.x - tree[i].y), {i, n}});
        pq.push({-(tree[i].x.y - tree[i].y), {i, n + 1}});
        pq.push({-(w - tree[i].x.x - tree[i].y), {i, n + 2}});
        pq.push({-(h - tree[i].x.y - tree[i].y), {i, n + 3}});
    }
    FOR(i, 0, m) {
        cin >> visitors[i].x.x >> visitors[i].x.y;
        visitors[i].y = i;
    }
    sort(visitors, visitors + m);

    // n: East wall
    // n+1: South wall
    // n+2: West wall
    // n+3: North wall
    FOR(i, 0, m) {
        while (-pq.top().x < 2 * visitors[i].x.x) {
            onion(pq.top().y.x, pq.top().y.y);
            pq.pop();
        }

        if (visitors[i].x.y == 1) {
            ans[visitors[i].y] += "1";
            if (find(n) != find(n + 1) && find(n + 1) != find(n + 3) && find(n + 1) != find(n + 2)) ans[visitors[i].y] += "2";
            if (find(n) != find(n + 2) && find(n) != find(n + 1) && find(n + 1) != find(n + 3) && find(n + 2) != find(n + 3)) ans[visitors[i].y] += "3";
            if (find(n) != find(n + 1) && find(n) != find(n + 2) && find(n) != find(n + 3)) ans[visitors[i].y] += "4";
        } else if (visitors[i].x.y == 2) {
            if (find(n) != find(n + 1) && find(n + 1) != find(n + 3) && find(n + 1) != find(n + 2)) ans[visitors[i].y] += "1";
            ans[visitors[i].y] += "2";
            if (find(n) != find(n + 2) && find(n + 1) != find(n + 2) && find(n + 3) != find(n + 2)) ans[visitors[i].y] += "3";
            if (find(n) != find(n + 2) && find(n + 1) != find(n + 3) && find(n + 1) != find(n + 2) && find(n) != find(n + 3)) ans[visitors[i].y] += "4";
        } else if (visitors[i].x.y == 3) {
            if (find(n) != find(n + 2) && find(n) != find(n + 1) && find(n + 1) != find(n + 3) && find(n + 2) != find(n + 3)) ans[visitors[i].y] += "1";
            if (find(n) != find(n + 2) && find(n + 1) != find(n + 2) && find(n + 3) != find(n + 2)) ans[visitors[i].y] += "2";
            ans[visitors[i].y] += "3";
            if (find(n) != find(n + 3) && find(n + 1) != find(n + 3) && find(n + 2) != find(n + 3)) ans[visitors[i].y] += "4";
        } else {
            if (find(n) != find(n + 1) && find(n) != find(n + 2) && find(n) != find(n + 3)) ans[visitors[i].y] += "1";
            if (find(n) != find(n + 2) && find(n + 1) != find(n + 3) && find(n + 1) != find(n + 2) && find(n) != find(n + 3)) ans[visitors[i].y] += "2";
            if (find(n) != find(n + 3) && find(n + 1) != find(n + 3) && find(n + 2) != find(n + 3)) ans[visitors[i].y] += "3";
            ans[visitors[i].y] += "4";
        }
    }

    FOR(i, 0, m) cout << ans[i] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 185 ms 52908 KB Output is correct
2 Correct 183 ms 53036 KB Output is correct
3 Correct 202 ms 52908 KB Output is correct
4 Correct 185 ms 53032 KB Output is correct
5 Correct 186 ms 53036 KB Output is correct
6 Correct 188 ms 52960 KB Output is correct
7 Correct 711 ms 53000 KB Output is correct
8 Correct 175 ms 53012 KB Output is correct
9 Correct 5 ms 3448 KB Output is correct
10 Correct 5 ms 3452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 6888 KB Output is correct
2 Correct 58 ms 7916 KB Output is correct
3 Correct 56 ms 7916 KB Output is correct
4 Correct 57 ms 7920 KB Output is correct
5 Correct 58 ms 7892 KB Output is correct
6 Correct 59 ms 7920 KB Output is correct
7 Correct 54 ms 7288 KB Output is correct
8 Correct 61 ms 7288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 52908 KB Output is correct
2 Correct 183 ms 53036 KB Output is correct
3 Correct 202 ms 52908 KB Output is correct
4 Correct 185 ms 53032 KB Output is correct
5 Correct 186 ms 53036 KB Output is correct
6 Correct 188 ms 52960 KB Output is correct
7 Correct 711 ms 53000 KB Output is correct
8 Correct 175 ms 53012 KB Output is correct
9 Correct 5 ms 3448 KB Output is correct
10 Correct 5 ms 3452 KB Output is correct
11 Correct 60 ms 6888 KB Output is correct
12 Correct 58 ms 7916 KB Output is correct
13 Correct 56 ms 7916 KB Output is correct
14 Correct 57 ms 7920 KB Output is correct
15 Correct 58 ms 7892 KB Output is correct
16 Correct 59 ms 7920 KB Output is correct
17 Correct 54 ms 7288 KB Output is correct
18 Correct 61 ms 7288 KB Output is correct
19 Correct 232 ms 54612 KB Output is correct
20 Correct 237 ms 54636 KB Output is correct
21 Correct 236 ms 54708 KB Output is correct
22 Correct 231 ms 54520 KB Output is correct
23 Correct 232 ms 54596 KB Output is correct
24 Correct 765 ms 54644 KB Output is correct