답안 #1039935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039935 2024-07-31T12:41:26 Z yanb 분수 공원 (IOI21_parks) C++17
25 / 100
909 ms 109776 KB
#include <bits/stdc++.h>
    
using namespace std;
    
//#define int long long
//#define pii pair<long long, long long>
#define pii pair<int, int>
#define pib pair<int, bool>
#define fi first
#define se second

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);

const int WHITE = 0, GRAY = 1, BLACK = 2;

void dfs(int v, vector<vector<int>> &g, vector<int> &uu) {
    if (uu[v]) return;
    uu[v] = 1;
    for (int u : g[v]) dfs(u, g, uu);
}

void follow(int v, vector<vector<int>> &h, vector<int> &a, vector<int> &b, map<pii, int> &mid, 
vector<pii> &pm, vector<int> &x, vector<int> &y) {
    if (h[v].empty()) return;
while (h[v].size()){
    int u = h[v].back();
    //cout << "Erasing " << pm[v].fi << "," << pm[v].se << " ~ " << pm[u].fi << "," << pm[u].se << "\n";
    h[v].erase(remove(h[v].begin(), h[v].end(), u), h[v].end());
    h[u].erase(remove(h[u].begin(), h[u].end(), v), h[u].end());
    int pd = mid[{(pm[v].fi + pm[u].fi) / 2, (pm[v].se + pm[u].se) / 2}];
    a[pd] = pm[u].fi;
    b[pd] = pm[u].se;
    follow(u, h, a, b, mid, pm, x, y);
}
}

int do_tree(vector<int> x, vector<int> y) {
    int n = x.size();
    map<pii, int> id, mid;
    for (int i = 0; i < n; i++) {
        id[{x[i], y[i]}] = i;
    }

    vector<vector<int>> g(n);
    for (int i = 0; i < n; i++) {
        if (id.count({x[i] + 2, y[i]})) g[i].push_back(id[{x[i] + 2, y[i]}]);
        if (id.count({x[i] - 2, y[i]})) g[i].push_back(id[{x[i] - 2, y[i]}]);
        if (id.count({x[i], y[i] + 2})) g[i].push_back(id[{x[i], y[i] + 2}]);
        if (id.count({x[i], y[i] - 2})) g[i].push_back(id[{x[i], y[i] - 2}]);
    }

    vector<int> uu(n, false);
    dfs(0, g, uu);
    for (int i = 0; i < n; i++) {
        if (!uu[i]) return 0;
    }
    
    int ec = 0;
    for (auto& edges : g) ec += edges.size();
    
    int expected_ec = 2 * ((int)g.size() - 1);
    assert(ec == expected_ec);

    vector<int> bu, bv;
    int cnt = 0;
    for (int u = 0; u < n; u++) {
        for (int v : g[u]) {
            if (v > u) {
                bv.push_back(v);
                bu.push_back(u);
                mid[{(x[v] + x[u]) / 2, (y[v] + y[u]) / 2}] = cnt;
                cnt++;
            }
        }
    }

    cnt = 0;
    map<pii, int> mp;
    vector<pii> pm;
    vector<vector<int>> h;
    for (int v = 0; v < n; v++) {
        for (int u : g[v]) {
            int xm = (x[v] + x[u]) / 2, ym = (y[v] + y[u]) / 2;
            pii p = {xm + (ym - y[v]), ym + (xm - x[v])}; 
            pii q = {xm + (ym - y[u]), ym + (xm - x[u])}; 
            if (!mp.count(p)) {
                mp[p] = cnt;
                h.push_back({});
                pm.push_back(p);
                cnt++;
            }
            if (!mp.count(q)) {
                mp[q] = cnt;
                h.push_back({});
                pm.push_back(q);
                cnt++;
            }
            h[mp[p]].push_back(mp[q]);
        }
    }
    
    
    
    // for (int v = 0; v < cnt; ++v) if (h[v].size() > 2) return 0;
    
    // for (int v = 0; v < cnt; ++v) {
    //     cout << pm[v].first << " " << pm[v].second << "\n";
    //     std::cout << "Start edges" << "\n";
    //     for (int to : h[v]) std::cout << to << " ";
    //     std::cout << "\n";
    // }

    vector<int> a(n - 1), b(n - 1);
    for (int i = 0; i < cnt; i++) {
        follow(i, h, a, b, mid, pm, x, y);
    }

    build(bu, bv, a, b);

    return 1;
}

int construct_roads(vector<int> x, vector<int> y) {
    return do_tree(x, y);
}

#ifdef ONLINE_JUDGE
void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b) {
    int n = u.size();
    for (int i = 0; i < n; i++) cout << u[i] << " ";
    cout << "\n";
    for (int i = 0; i < n; i++) cout << v[i] << " ";
    cout << "\n";
    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << "\n";
    for (int i = 0; i < n; i++) cout << b[i] << " ";
    cout << "\n";
}

signed main() {
    construct_roads({2, 2, 4}, {2, 4, 2});
    //construct_roads({4, 4, 6, 4, 2}, {4, 6, 4, 2, 4});
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 323 ms 55028 KB Output is correct
10 Correct 20 ms 5904 KB Output is correct
11 Correct 114 ms 29936 KB Output is correct
12 Correct 27 ms 8468 KB Output is correct
13 Correct 29 ms 8024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 344 ms 53208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 323 ms 55028 KB Output is correct
10 Correct 20 ms 5904 KB Output is correct
11 Correct 114 ms 29936 KB Output is correct
12 Correct 27 ms 8468 KB Output is correct
13 Correct 29 ms 8024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 344 ms 53208 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 323 ms 55028 KB Output is correct
10 Correct 20 ms 5904 KB Output is correct
11 Correct 114 ms 29936 KB Output is correct
12 Correct 27 ms 8468 KB Output is correct
13 Correct 29 ms 8024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 344 ms 53208 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 323 ms 55028 KB Output is correct
10 Correct 20 ms 5904 KB Output is correct
11 Correct 114 ms 29936 KB Output is correct
12 Correct 27 ms 8468 KB Output is correct
13 Correct 29 ms 8024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 344 ms 53208 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 685 ms 109776 KB Output is correct
21 Correct 700 ms 86056 KB Output is correct
22 Correct 679 ms 87592 KB Output is correct
23 Correct 665 ms 91208 KB Output is correct
24 Correct 177 ms 23116 KB Output is correct
25 Correct 283 ms 29268 KB Output is correct
26 Correct 256 ms 29520 KB Output is correct
27 Correct 827 ms 101260 KB Output is correct
28 Correct 845 ms 101248 KB Output is correct
29 Correct 909 ms 101328 KB Output is correct
30 Correct 887 ms 101180 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 35 ms 6576 KB Output is correct
33 Correct 77 ms 11576 KB Output is correct
34 Correct 699 ms 104236 KB Output is correct
35 Correct 9 ms 1880 KB Output is correct
36 Correct 57 ms 7544 KB Output is correct
37 Correct 134 ms 14676 KB Output is correct
38 Correct 260 ms 32704 KB Output is correct
39 Correct 381 ms 44724 KB Output is correct
40 Correct 506 ms 56876 KB Output is correct
41 Correct 652 ms 68872 KB Output is correct
42 Correct 820 ms 80940 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 372 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 344 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 2 ms 604 KB Output is correct
55 Correct 2 ms 648 KB Output is correct
56 Correct 343 ms 45820 KB Output is correct
57 Correct 547 ms 66736 KB Output is correct
58 Correct 540 ms 66600 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 800 ms 108056 KB Output is correct
63 Correct 776 ms 108244 KB Output is correct
64 Correct 762 ms 108556 KB Output is correct
65 Correct 3 ms 856 KB Output is correct
66 Correct 6 ms 1628 KB Output is correct
67 Correct 324 ms 44492 KB Output is correct
68 Correct 543 ms 66856 KB Output is correct
69 Correct 796 ms 88736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 323 ms 55028 KB Output is correct
10 Correct 20 ms 5904 KB Output is correct
11 Correct 114 ms 29936 KB Output is correct
12 Correct 27 ms 8468 KB Output is correct
13 Correct 29 ms 8024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 344 ms 53208 KB Output is correct
17 Runtime error 275 ms 78160 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 323 ms 55028 KB Output is correct
10 Correct 20 ms 5904 KB Output is correct
11 Correct 114 ms 29936 KB Output is correct
12 Correct 27 ms 8468 KB Output is correct
13 Correct 29 ms 8024 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 344 ms 53208 KB Output is correct
17 Runtime error 1 ms 348 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -