답안 #751124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751124 2023-05-31T05:04:06 Z drdilyor Drawing (CEOI22_drawing) C++17
100 / 100
663 ms 80772 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
mt19937 rng;

using pt = pair<int,int>;
bool ccw(pt A, pt B, pt C) {
    return ll(C.second-A.second) * (B.first-A.first) > ll(B.second-A.second) * (C.first-A.first);
}
bool intersect(pt A, pt B, pt C, pt D) {
    return ccw(A, C, D) != ccw(B, C, D) && ccw(A, B, C) != ccw(A, B, D);
}

int main() {

    int n;
    cin >> n;

    vector<vector<int>> adj(n);
    vector<pair<int,int>> pts(n);
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        u--;v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    map<pair<int,int>, int> ix;
    for (auto& [x, y] : pts)
        cin >> x >> y;
    for (int i = 0; i < n; i++)
        ix[pts[i]]= i;

    int r = 0;
    for (; r < n; r++)
        if (adj[r].size() < 3) break;

    vector<int> res(n, -1);
    vector<int> subs(n, 1);
    auto dfs_sz = [&](auto& dfs_sz, int i, int p=-1)->void {
        for (int e : adj[i]) if (e != p) {
            dfs_sz(dfs_sz, e, i);
            subs[i] += subs[e];
        }
    };
    dfs_sz(dfs_sz, r);

    auto dfs = [&](auto& dfs, vector<pair<int,int>>::iterator p1, vector<pair<int,int>>::iterator p2, int i, int p =-1)->void {
        vector<int> ch;
        for (int e : adj[i]) {
            if (e != p) ch.push_back(e);
        }
        if (ch.empty()) {
            assert(p1 == p2);
            return;
        }
        if (ch.size() == 1) {
            res[ch[0]] = ix[*p1++];
            dfs(dfs, p1, p2, ch[0], i);
        } else {
            //sort(p1, p2, [](const auto& p, const auto& q)->bool { return (ll)p.second * q.first > (ll) q.second * p.first; });
            assert(p2 - p1 == subs[ch[0]] + subs[ch[1]]);
            auto q1 = p1 + subs[ch[0]];
            auto q2 = p2;
            p2 = q1;
            //sort(p1, p2, greater());
            //sort(q1, q2, greater());
            res[ch[0]] = ix[*p1++];
            res[ch[1]] = ix[*q1++];
            dfs(dfs, p1, p2, ch[0], i);
            dfs(dfs, q1, q2, ch[1], i);
        }
    };

    auto p1 = pts.begin(),
         p2 = pts.end();
    sort(pts.begin(), pts.end());
    res[r] = ix[*p1++];
    dfs(dfs, p1, p2, r);

    vector<int> byp(n);
    for (int i = 0; i < n; i++)
        assert(res[i] >= 0),
        byp[res[i]] = i;
    for (int i : byp) {
        cout << i+1 << ' ';
    }
    cout << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 20004 KB Output is correct
2 Correct 331 ms 33608 KB Output is correct
3 Correct 310 ms 28588 KB Output is correct
4 Correct 339 ms 40392 KB Output is correct
5 Correct 303 ms 42628 KB Output is correct
6 Correct 308 ms 19788 KB Output is correct
7 Correct 337 ms 22536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 852 KB Output is correct
2 Correct 9 ms 1236 KB Output is correct
3 Correct 10 ms 1236 KB Output is correct
4 Correct 9 ms 1748 KB Output is correct
5 Correct 12 ms 1620 KB Output is correct
6 Correct 8 ms 952 KB Output is correct
7 Correct 9 ms 1108 KB Output is correct
8 Correct 9 ms 948 KB Output is correct
9 Correct 9 ms 1364 KB Output is correct
10 Correct 10 ms 1108 KB Output is correct
11 Correct 8 ms 1624 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 8 ms 956 KB Output is correct
14 Correct 9 ms 1248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 852 KB Output is correct
2 Correct 9 ms 1236 KB Output is correct
3 Correct 10 ms 1236 KB Output is correct
4 Correct 9 ms 1748 KB Output is correct
5 Correct 12 ms 1620 KB Output is correct
6 Correct 8 ms 952 KB Output is correct
7 Correct 9 ms 1108 KB Output is correct
8 Correct 9 ms 948 KB Output is correct
9 Correct 9 ms 1364 KB Output is correct
10 Correct 10 ms 1108 KB Output is correct
11 Correct 8 ms 1624 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 8 ms 956 KB Output is correct
14 Correct 9 ms 1248 KB Output is correct
15 Correct 22 ms 1992 KB Output is correct
16 Correct 22 ms 3116 KB Output is correct
17 Correct 21 ms 2372 KB Output is correct
18 Correct 21 ms 4104 KB Output is correct
19 Correct 22 ms 3916 KB Output is correct
20 Correct 21 ms 1988 KB Output is correct
21 Correct 20 ms 2636 KB Output is correct
22 Correct 21 ms 1996 KB Output is correct
23 Correct 22 ms 2600 KB Output is correct
24 Correct 21 ms 2380 KB Output is correct
25 Correct 22 ms 4016 KB Output is correct
26 Correct 20 ms 3668 KB Output is correct
27 Correct 21 ms 1944 KB Output is correct
28 Correct 22 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 852 KB Output is correct
2 Correct 9 ms 1236 KB Output is correct
3 Correct 10 ms 1236 KB Output is correct
4 Correct 9 ms 1748 KB Output is correct
5 Correct 12 ms 1620 KB Output is correct
6 Correct 8 ms 952 KB Output is correct
7 Correct 9 ms 1108 KB Output is correct
8 Correct 9 ms 948 KB Output is correct
9 Correct 9 ms 1364 KB Output is correct
10 Correct 10 ms 1108 KB Output is correct
11 Correct 8 ms 1624 KB Output is correct
12 Correct 8 ms 1364 KB Output is correct
13 Correct 8 ms 956 KB Output is correct
14 Correct 9 ms 1248 KB Output is correct
15 Correct 22 ms 1992 KB Output is correct
16 Correct 22 ms 3116 KB Output is correct
17 Correct 21 ms 2372 KB Output is correct
18 Correct 21 ms 4104 KB Output is correct
19 Correct 22 ms 3916 KB Output is correct
20 Correct 21 ms 1988 KB Output is correct
21 Correct 20 ms 2636 KB Output is correct
22 Correct 21 ms 1996 KB Output is correct
23 Correct 22 ms 2600 KB Output is correct
24 Correct 21 ms 2380 KB Output is correct
25 Correct 22 ms 4016 KB Output is correct
26 Correct 20 ms 3668 KB Output is correct
27 Correct 21 ms 1944 KB Output is correct
28 Correct 22 ms 2512 KB Output is correct
29 Correct 233 ms 14156 KB Output is correct
30 Correct 207 ms 23808 KB Output is correct
31 Correct 217 ms 19148 KB Output is correct
32 Correct 222 ms 30540 KB Output is correct
33 Correct 225 ms 26868 KB Output is correct
34 Correct 196 ms 14120 KB Output is correct
35 Correct 206 ms 16872 KB Output is correct
36 Correct 155 ms 12208 KB Output is correct
37 Correct 203 ms 20776 KB Output is correct
38 Correct 249 ms 20172 KB Output is correct
39 Correct 229 ms 26864 KB Output is correct
40 Correct 215 ms 23028 KB Output is correct
41 Correct 191 ms 12296 KB Output is correct
42 Correct 203 ms 17028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 20004 KB Output is correct
2 Correct 331 ms 33608 KB Output is correct
3 Correct 310 ms 28588 KB Output is correct
4 Correct 339 ms 40392 KB Output is correct
5 Correct 303 ms 42628 KB Output is correct
6 Correct 308 ms 19788 KB Output is correct
7 Correct 337 ms 22536 KB Output is correct
8 Correct 9 ms 852 KB Output is correct
9 Correct 9 ms 1236 KB Output is correct
10 Correct 10 ms 1236 KB Output is correct
11 Correct 9 ms 1748 KB Output is correct
12 Correct 12 ms 1620 KB Output is correct
13 Correct 8 ms 952 KB Output is correct
14 Correct 9 ms 1108 KB Output is correct
15 Correct 9 ms 948 KB Output is correct
16 Correct 9 ms 1364 KB Output is correct
17 Correct 10 ms 1108 KB Output is correct
18 Correct 8 ms 1624 KB Output is correct
19 Correct 8 ms 1364 KB Output is correct
20 Correct 8 ms 956 KB Output is correct
21 Correct 9 ms 1248 KB Output is correct
22 Correct 22 ms 1992 KB Output is correct
23 Correct 22 ms 3116 KB Output is correct
24 Correct 21 ms 2372 KB Output is correct
25 Correct 21 ms 4104 KB Output is correct
26 Correct 22 ms 3916 KB Output is correct
27 Correct 21 ms 1988 KB Output is correct
28 Correct 20 ms 2636 KB Output is correct
29 Correct 21 ms 1996 KB Output is correct
30 Correct 22 ms 2600 KB Output is correct
31 Correct 21 ms 2380 KB Output is correct
32 Correct 22 ms 4016 KB Output is correct
33 Correct 20 ms 3668 KB Output is correct
34 Correct 21 ms 1944 KB Output is correct
35 Correct 22 ms 2512 KB Output is correct
36 Correct 233 ms 14156 KB Output is correct
37 Correct 207 ms 23808 KB Output is correct
38 Correct 217 ms 19148 KB Output is correct
39 Correct 222 ms 30540 KB Output is correct
40 Correct 225 ms 26868 KB Output is correct
41 Correct 196 ms 14120 KB Output is correct
42 Correct 206 ms 16872 KB Output is correct
43 Correct 155 ms 12208 KB Output is correct
44 Correct 203 ms 20776 KB Output is correct
45 Correct 249 ms 20172 KB Output is correct
46 Correct 229 ms 26864 KB Output is correct
47 Correct 215 ms 23028 KB Output is correct
48 Correct 191 ms 12296 KB Output is correct
49 Correct 203 ms 17028 KB Output is correct
50 Correct 358 ms 22096 KB Output is correct
51 Correct 617 ms 58656 KB Output is correct
52 Correct 621 ms 45000 KB Output is correct
53 Correct 625 ms 64528 KB Output is correct
54 Correct 614 ms 80772 KB Output is correct
55 Correct 580 ms 35340 KB Output is correct
56 Correct 643 ms 40388 KB Output is correct
57 Correct 98 ms 7652 KB Output is correct
58 Correct 663 ms 48924 KB Output is correct
59 Correct 575 ms 44776 KB Output is correct
60 Correct 580 ms 77804 KB Output is correct
61 Correct 615 ms 60196 KB Output is correct
62 Correct 106 ms 7688 KB Output is correct
63 Correct 623 ms 40060 KB Output is correct