답안 #1050560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050560 2024-08-09T11:06:48 Z Zicrus 분수 공원 (IOI21_parks) C++17
15 / 100
206 ms 50164 KB
#include <bits/stdc++.h>
#include "parks.h"
using namespace std;

typedef long long ll;

ll n;

vector<ll> lnk;
vector<ll> sz;

ll find(ll a) {
    if (a != lnk[a]) lnk[a] = find(lnk[a]);
    return lnk[a];
}

bool unite(ll a, ll b) {
    a = find(a); b = find(b);
    if (a == b) return false;
    if (sz[a] > sz[b]) swap(a, b);
    lnk[a] = b;
    sz[b] += sz[a];
    return true;
}

int construct_roads(vector<int> x, vector<int> y) {
    n = x.size();
    lnk = vector<ll>(n);
    sz = vector<ll>(n, 1);
    for (int i = 0; i < n; i++) lnk[i] = i;
    unordered_map<ll, ll> pts;
    vector<pair<ll, ll>> edges;
    unordered_set<ll> hasEdge;
    for (int i = 0; i < n; i++) {
        ll hash = ((ll)x[i] << 31) | (ll)y[i];
        pts[hash] = i;
    }
    for (ll i = 0; i < n; i++) {
        ll hashL = (((ll)x[i]-2) << 31) | ((ll)y[i]);
        if (pts.count(hashL)) {
            ll hash = (min(i, pts[hashL]) << 31) | max(i, pts[hashL]);
            if (!hasEdge.count(hash)) {
                edges.push_back({i, pts[hashL]});
                hasEdge.insert(hash);
            }
        }
        ll hashR = (((ll)x[i]+2) << 31) | ((ll)y[i]);
        if (pts.count(hashR)) {
            ll hash = (min(i, pts[hashR]) << 31) | max(i, pts[hashR]);
            if (!hasEdge.count(hash)) {
                edges.push_back({i, pts[hashR]});
                hasEdge.insert(hash);
            }
        }
        ll hashD = (((ll)x[i]) << 31) | ((ll)y[i]-2);
        if (pts.count(hashD)) {
            ll hash = (min(i, pts[hashD]) << 31) | max(i, pts[hashD]);
            if (!hasEdge.count(hash)) {
                edges.push_back({i, pts[hashD]});
                hasEdge.insert(hash);
            }
        }
        ll hashU = (((ll)x[i]) << 31) | ((ll)y[i]+2);
        if (pts.count(hashU)) {
            ll hash = (min(i, pts[hashU]) << 31) | max(i, pts[hashU]);
            if (!hasEdge.count(hash)) {
                edges.push_back({i, pts[hashU]});
                hasEdge.insert(hash);
            }
        }
    }

    vector<int> u, v, a, b;
    for (auto &e : edges) {
        unite(e.first, e.second);
        u.push_back(e.first);
        v.push_back(e.second);
        if (x[e.first] == 2 && x[e.second] == 2) {
            a.push_back(1);
            b.push_back((y[e.first] + y[e.second]) / 2);
        }
        else if (x[e.first] == 4 && x[e.second] == 4) {
            a.push_back(5);
            b.push_back((y[e.first] + y[e.second]) / 2);
        }
        else {
            a.push_back(3);
            b.push_back(y[e.first] + 1);
        }
    }

    if (sz[find(0)] < n) return 0;

    build(u, v, a, b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 63 ms 19704 KB Output is correct
10 Correct 4 ms 2100 KB Output is correct
11 Correct 22 ms 10128 KB Output is correct
12 Correct 6 ms 3032 KB Output is correct
13 Correct 12 ms 7784 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 62 ms 19768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 63 ms 19704 KB Output is correct
10 Correct 4 ms 2100 KB Output is correct
11 Correct 22 ms 10128 KB Output is correct
12 Correct 6 ms 3032 KB Output is correct
13 Correct 12 ms 7784 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 62 ms 19768 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 206 ms 50164 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 69 ms 18820 KB Output is correct
29 Correct 116 ms 30868 KB Output is correct
30 Correct 169 ms 37232 KB Output is correct
31 Correct 201 ms 49660 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 72 ms 19708 KB Output is correct
46 Correct 110 ms 28324 KB Output is correct
47 Correct 120 ms 27388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 63 ms 19704 KB Output is correct
10 Correct 4 ms 2100 KB Output is correct
11 Correct 22 ms 10128 KB Output is correct
12 Correct 6 ms 3032 KB Output is correct
13 Correct 12 ms 7784 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 62 ms 19768 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 206 ms 50164 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 69 ms 18820 KB Output is correct
29 Correct 116 ms 30868 KB Output is correct
30 Correct 169 ms 37232 KB Output is correct
31 Correct 201 ms 49660 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 72 ms 19708 KB Output is correct
46 Correct 110 ms 28324 KB Output is correct
47 Correct 120 ms 27388 KB Output is correct
48 Incorrect 0 ms 344 KB Tree (a[0], b[0]) = (3, 3) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=1 @(4, 2)
49 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 63 ms 19704 KB Output is correct
10 Correct 4 ms 2100 KB Output is correct
11 Correct 22 ms 10128 KB Output is correct
12 Correct 6 ms 3032 KB Output is correct
13 Correct 12 ms 7784 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 62 ms 19768 KB Output is correct
17 Incorrect 1 ms 600 KB Tree (a[0], b[0]) = (3, 3) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=2 @(199998, 2)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 63 ms 19704 KB Output is correct
10 Correct 4 ms 2100 KB Output is correct
11 Correct 22 ms 10128 KB Output is correct
12 Correct 6 ms 3032 KB Output is correct
13 Correct 12 ms 7784 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 62 ms 19768 KB Output is correct
17 Incorrect 163 ms 40212 KB Tree (a[0], b[0]) = (3, 100003) is not adjacent to edge between u[0]=0 @(82422, 100002) and v[0]=148989 @(82420, 100002)
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 63 ms 19704 KB Output is correct
10 Correct 4 ms 2100 KB Output is correct
11 Correct 22 ms 10128 KB Output is correct
12 Correct 6 ms 3032 KB Output is correct
13 Correct 12 ms 7784 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 62 ms 19768 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 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 206 ms 50164 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 69 ms 18820 KB Output is correct
29 Correct 116 ms 30868 KB Output is correct
30 Correct 169 ms 37232 KB Output is correct
31 Correct 201 ms 49660 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 72 ms 19708 KB Output is correct
46 Correct 110 ms 28324 KB Output is correct
47 Correct 120 ms 27388 KB Output is correct
48 Incorrect 0 ms 344 KB Tree (a[0], b[0]) = (3, 3) is not adjacent to edge between u[0]=0 @(6, 2) and v[0]=1 @(4, 2)
49 Halted 0 ms 0 KB -