답안 #339179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339179 2020-12-24T19:07:15 Z 12tqian Park (BOI16_park) C++17
100 / 100
774 ms 66488 KB
#include <bits/stdc++.h>
using namespace std;

#define f1r(i, a, b) for (int i = a; i < b; i++) 
#define f0r(i, a) f1r(i, 0, a)

#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

struct DSU {
    std::vector<int> e;
    void init(int n) {
        e = std::vector<int>(n, -1);
    }
    int get(int x) {
        return e[x] < 0 ? x : e[x] = get(e[x]);
    }
    bool same_set(int a, int b) {
        return get(a) == get(b);
    }
    int size(int x) {
        return -e[get(x)];
    }
    bool unite(int x, int y) {
        x = get(x), y = get(y);
        if (x == y) return false;
        if (e[x] > e[y]) std::swap(x, y);
        e[x] += e[y]; e[y] = x;
        return true;
    }
};

ll sq(ll x) {
    return x*x;
}
ld dist(pi x, pi y) {
    return sqrt(sq(x.f-y.f)+sq(x.s-y.s));
}
ld gap(array<int, 3> a, array<int, 3> b) {
    return (dist({a[0], a[1]}, {b[0], b[1]}) - a[2] - b[2])/2;
}
template <class T> bool ckmin(T& x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
ld ti[4][4]; // diameter squared of first time there is a path
struct Edge {
    ld w;
    int u, v;
};
int main() {
    const ll INF = 9e18;
    cin.tie(0)->sync_with_stdio(0);
    int n, m; cin >> n >> m;
    int w, h; cin >> w >> h;
    vector<array<int, 3>> trees(n);
    f0r(i, n) 
        cin >> trees[i][0] >> trees[i][1] >> trees[i][2];
    // n, n+1, n+2, n+3
    // 0, 1, 2, 3
    // S, E, N, W
    DSU D; D.init(n+4);
    vector<Edge> ed;
    f0r(i, n) {
        f1r(j, i+1, n) {
            ed.pb({gap(trees[i], trees[j]), i, j});
        }
        ld x = trees[i][0];
        ld y = trees[i][1];
        ld r = trees[i][2];
        ed.pb({(x-r)/2, i, n+3});
        ed.pb({(w-x-r)/2, i, n+1});
        ed.pb({(y-r)/2, i, n});        
        ed.pb({(h-y-r)/2, i, n+2});
    }
    sort(all(ed), [](Edge& e1, Edge& e2) { return e1.w<e2.w; });
    f0r(i, 4) f0r(j, 4) ti[i][j] = INF;
    for (auto& e : ed) {
        ld w = e.w;
        int u = e.u;
        int v = e.v;
        D.unite(u, v);
        f0r(i, 4) {
            f0r(j, 4) {
                if (D.same_set(n+i, n+j)) {
                    ckmin(ti[i][j], w);
                    ckmin(ti[j][i], w);
                }
            }
        }
    }
    f0r(i, m) {
        ll st, r; cin >> r >> st;
        st--;
        vi res;
        f0r(to, 4) {
            if (to == st) {
                res.eb(to);
            } else {
                // st, to-1
                int w1 = st;
                while (w1 != to) {
                    int w2 = to;
                    while (w2 != st) {
                        ld t = ti[w1][w2];
                        if (t < r) {
                            goto fail;
                        }
                        w2++;
                        w2 %= 4;
                    }
                    w1++;
                    w1 %= 4;
                }
                res.eb(to);
                fail: 
                    continue;
            }
        }
        for (auto x : res) cout << x+1;
        cout << '\n';
    }   
}

// 15, 5, 1
// 11 8 1
// 
# 결과 실행 시간 메모리 Grader output
1 Correct 721 ms 66228 KB Output is correct
2 Correct 719 ms 66196 KB Output is correct
3 Correct 717 ms 66196 KB Output is correct
4 Correct 723 ms 66196 KB Output is correct
5 Correct 719 ms 66324 KB Output is correct
6 Correct 728 ms 66324 KB Output is correct
7 Correct 621 ms 66340 KB Output is correct
8 Correct 614 ms 66196 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 56 ms 2532 KB Output is correct
2 Correct 53 ms 2532 KB Output is correct
3 Correct 52 ms 2532 KB Output is correct
4 Correct 54 ms 2532 KB Output is correct
5 Correct 55 ms 2532 KB Output is correct
6 Correct 61 ms 2532 KB Output is correct
7 Correct 45 ms 1772 KB Output is correct
8 Correct 43 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 721 ms 66228 KB Output is correct
2 Correct 719 ms 66196 KB Output is correct
3 Correct 717 ms 66196 KB Output is correct
4 Correct 723 ms 66196 KB Output is correct
5 Correct 719 ms 66324 KB Output is correct
6 Correct 728 ms 66324 KB Output is correct
7 Correct 621 ms 66340 KB Output is correct
8 Correct 614 ms 66196 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 56 ms 2532 KB Output is correct
12 Correct 53 ms 2532 KB Output is correct
13 Correct 52 ms 2532 KB Output is correct
14 Correct 54 ms 2532 KB Output is correct
15 Correct 55 ms 2532 KB Output is correct
16 Correct 61 ms 2532 KB Output is correct
17 Correct 45 ms 1772 KB Output is correct
18 Correct 43 ms 1772 KB Output is correct
19 Correct 771 ms 66452 KB Output is correct
20 Correct 768 ms 66480 KB Output is correct
21 Correct 774 ms 66452 KB Output is correct
22 Correct 759 ms 66488 KB Output is correct
23 Correct 762 ms 66452 KB Output is correct
24 Correct 665 ms 66452 KB Output is correct