답안 #750672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750672 2023-05-30T06:02:49 Z drdilyor Drawing (CEOI22_drawing) C++17
10 / 100
296 ms 24016 KB
#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;

    vector<int> res(n, -1);
    while (true) {
        vector<pt> hull;
        sort(pts.begin(), pts.end());
        for (int i = 0; i < (int)pts.size();i ++) {
            while (hull.size() >= 2) {
                if (!ccw(hull.end()[-2], hull.end()[-1], pts[i]))
                    hull.pop_back();
                else break;
            }
            hull.push_back(pts[i]);
        }
        auto down = hull;
        hull = {};
        for (int i = (int)pts.size()-1; i >= 0; i--) {
            while (hull.size() >= 2) {
                if (!ccw(hull.end()[-2], hull.end()[-1], pts[i]))
                    hull.pop_back();
                else break;
            }
            hull.push_back(pts[i]);
        }
        for (int i = 1; i < (int)down.size()-1; i++) {
            hull.push_back(down[i]);
        }

        auto dfs = [&](auto& dfs, int i, int p)->void{
            res[i] = ix[hull.back()];
            hull.pop_back();
            for (int e : adj[i]) {
                if (e == p) continue;
                dfs(dfs, e, i);
            }
        };
        dfs(dfs, 0, -1);
        break;
    }
    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 259 ms 16612 KB Output is correct
2 Correct 260 ms 21760 KB Output is correct
3 Correct 267 ms 20816 KB Output is correct
4 Correct 296 ms 24016 KB Output is correct
5 Correct 251 ms 21896 KB Output is correct
6 Correct 263 ms 20032 KB Output is correct
7 Correct 264 ms 20040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 852 KB Output is correct
2 Incorrect 8 ms 952 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 852 KB Output is correct
2 Incorrect 8 ms 952 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 852 KB Output is correct
2 Incorrect 8 ms 952 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 16612 KB Output is correct
2 Correct 260 ms 21760 KB Output is correct
3 Correct 267 ms 20816 KB Output is correct
4 Correct 296 ms 24016 KB Output is correct
5 Correct 251 ms 21896 KB Output is correct
6 Correct 263 ms 20032 KB Output is correct
7 Correct 264 ms 20040 KB Output is correct
8 Correct 7 ms 852 KB Output is correct
9 Incorrect 8 ms 952 KB Output isn't correct
10 Halted 0 ms 0 KB -