Submission #579216

# Submission time Handle Problem Language Result Execution time Memory
579216 2022-06-18T13:33:36 Z KoD Fountain Parks (IOI21_parks) C++17
30 / 100
460 ms 38824 KB
#include "parks.h"
#include <bits/stdc++.h>

using std::array;
using std::pair;
using std::tuple;
using std::vector;

using ll = long long;

template <class T>
constexpr T infty = std::numeric_limits<T>::max() / 2;

template <class F>
struct fixed : private F {
    explicit fixed(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args>
    decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

struct UnionFind {
    vector<int> data;
    explicit UnionFind(const int n) : data(n, -1) {}
    int find(const int u) {
        return data[u] < 0 ? u : data[u] = find(data[u]);
    }
    bool merge(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (data[x] > data[y]) std::swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
};

int construct_roads(vector<int> X, vector<int> Y) {
    const int N = (int)X.size();
    std::map<pair<int, int>, int> map;
    for (int i = 0; i < N; ++i) {
        map[{X[i], Y[i]}] = i;
    }
    UnionFind dsu(N);
    vector<array<int, 4>> edges;

    vector<int> up(N, -1), left(N, -1), right(N, -1);
    
    for (const auto& [p, i] : map) {
        const auto& [x, y] = p;
        const auto itr = map.find(pair(x, y + 2));
        if (itr != map.end()) {
            const int j = itr->second;
            if (!dsu.merge(i, j)) {
                continue;
            }
            if (x == 2) {
                edges.push_back({i, j, x - 1, y + 1});
            } else if (x == 6) {
                edges.push_back({i, j, x + 1, y + 1});
            } else {
                up[i] = (int)edges.size();
                edges.push_back({i, j, -1, -1});
            }
        }
    }

    for (const auto& [p, i] : map) {
        const auto& [x, y] = p;
        const auto itr = map.find(pair(x + 2, y));
        if (itr != map.end()) {
            const int j = itr->second;
            if (!dsu.merge(i, j)) {
                continue;
            }
            if (x == 2) {
                left[j] = (int)edges.size();
                edges.push_back({i, j, -1, -1});
            } else {
                right[i] = (int)edges.size();
                edges.push_back({i, j, -1, -1});
            }
        }
    }

    if ((int)edges.size() != N - 1) {
        return 0;
    }

    std::set<pair<int, int>> used;
    for (const auto& [p, i] : map) {
        if (X[i] != 4) {
            continue;
        }
        if (left[i] != -1) {
            const int x = 3;
            const int y = used.find(pair(x, Y[i] - 1)) != used.end() ? Y[i] + 1 : Y[i] - 1;
            used.emplace(x, y);
            edges[left[i]][2] = x;
            edges[left[i]][3] = y;
        }
        if (right[i] != -1) {
            const int x = 5;
            const int y = used.find(pair(x, Y[i] - 1)) != used.end() ? Y[i] + 1 : Y[i] - 1;
            used.emplace(x, y);
            edges[right[i]][2] = x;
            edges[right[i]][3] = y;
        }
        if (up[i] != -1) {
            const int y = Y[i] + 1;
            const int x = used.find(pair(3, y)) != used.end() ? 5 : 3;
            used.emplace(x, y);
            edges[up[i]][2] = x;
            edges[up[i]][3] = y;
        }
    }

    vector<int> U, V, A, B;
    for (const auto& [u, v, a, b] : edges) {
        U.push_back(u);
        V.push_back(v);
        A.push_back(a);
        B.push_back(b);
    }
    build(U, V, A, B);

    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 107 ms 17088 KB Output is correct
10 Correct 10 ms 2008 KB Output is correct
11 Correct 56 ms 9288 KB Output is correct
12 Correct 14 ms 2836 KB Output is correct
13 Correct 29 ms 5940 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 138 ms 17124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 107 ms 17088 KB Output is correct
10 Correct 10 ms 2008 KB Output is correct
11 Correct 56 ms 9288 KB Output is correct
12 Correct 14 ms 2836 KB Output is correct
13 Correct 29 ms 5940 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 138 ms 17124 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 413 ms 38672 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 123 ms 15888 KB Output is correct
29 Correct 199 ms 23132 KB Output is correct
30 Correct 268 ms 31676 KB Output is correct
31 Correct 346 ms 38716 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 304 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 143 ms 20152 KB Output is correct
46 Correct 256 ms 30124 KB Output is correct
47 Correct 225 ms 30008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 107 ms 17088 KB Output is correct
10 Correct 10 ms 2008 KB Output is correct
11 Correct 56 ms 9288 KB Output is correct
12 Correct 14 ms 2836 KB Output is correct
13 Correct 29 ms 5940 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 138 ms 17124 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 413 ms 38672 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 123 ms 15888 KB Output is correct
29 Correct 199 ms 23132 KB Output is correct
30 Correct 268 ms 31676 KB Output is correct
31 Correct 346 ms 38716 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 304 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 143 ms 20152 KB Output is correct
46 Correct 256 ms 30124 KB Output is correct
47 Correct 225 ms 30008 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 300 KB Output is correct
55 Correct 330 ms 37092 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 2 ms 572 KB Output is correct
58 Correct 6 ms 1364 KB Output is correct
59 Correct 6 ms 1620 KB Output is correct
60 Correct 126 ms 18588 KB Output is correct
61 Correct 242 ms 26044 KB Output is correct
62 Correct 293 ms 31272 KB Output is correct
63 Correct 412 ms 37172 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 300 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 361 ms 33920 KB Output is correct
68 Correct 303 ms 34064 KB Output is correct
69 Correct 302 ms 33812 KB Output is correct
70 Correct 3 ms 724 KB Output is correct
71 Correct 6 ms 1324 KB Output is correct
72 Correct 147 ms 19488 KB Output is correct
73 Correct 263 ms 30000 KB Output is correct
74 Correct 403 ms 38824 KB Output is correct
75 Correct 324 ms 35824 KB Output is correct
76 Correct 381 ms 34040 KB Output is correct
77 Correct 5 ms 980 KB Output is correct
78 Correct 6 ms 1492 KB Output is correct
79 Correct 161 ms 19080 KB Output is correct
80 Correct 279 ms 29416 KB Output is correct
81 Correct 460 ms 38156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 107 ms 17088 KB Output is correct
10 Correct 10 ms 2008 KB Output is correct
11 Correct 56 ms 9288 KB Output is correct
12 Correct 14 ms 2836 KB Output is correct
13 Correct 29 ms 5940 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 138 ms 17124 KB Output is correct
17 Incorrect 1 ms 212 KB Tree (a[0], b[0]) = (-1, -1) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 107 ms 17088 KB Output is correct
10 Correct 10 ms 2008 KB Output is correct
11 Correct 56 ms 9288 KB Output is correct
12 Correct 14 ms 2836 KB Output is correct
13 Correct 29 ms 5940 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 138 ms 17124 KB Output is correct
17 Incorrect 427 ms 34304 KB Tree (a[50000], b[50000]) = (-1, -1) is not adjacent to edge between u[50000]=138413 @(100002, 2) and v[50000]=87394 @(100002, 4)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 107 ms 17088 KB Output is correct
10 Correct 10 ms 2008 KB Output is correct
11 Correct 56 ms 9288 KB Output is correct
12 Correct 14 ms 2836 KB Output is correct
13 Correct 29 ms 5940 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 138 ms 17124 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 413 ms 38672 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 123 ms 15888 KB Output is correct
29 Correct 199 ms 23132 KB Output is correct
30 Correct 268 ms 31676 KB Output is correct
31 Correct 346 ms 38716 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 304 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 143 ms 20152 KB Output is correct
46 Correct 256 ms 30124 KB Output is correct
47 Correct 225 ms 30008 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 300 KB Output is correct
55 Correct 330 ms 37092 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 2 ms 572 KB Output is correct
58 Correct 6 ms 1364 KB Output is correct
59 Correct 6 ms 1620 KB Output is correct
60 Correct 126 ms 18588 KB Output is correct
61 Correct 242 ms 26044 KB Output is correct
62 Correct 293 ms 31272 KB Output is correct
63 Correct 412 ms 37172 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 300 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 361 ms 33920 KB Output is correct
68 Correct 303 ms 34064 KB Output is correct
69 Correct 302 ms 33812 KB Output is correct
70 Correct 3 ms 724 KB Output is correct
71 Correct 6 ms 1324 KB Output is correct
72 Correct 147 ms 19488 KB Output is correct
73 Correct 263 ms 30000 KB Output is correct
74 Correct 403 ms 38824 KB Output is correct
75 Correct 324 ms 35824 KB Output is correct
76 Correct 381 ms 34040 KB Output is correct
77 Correct 5 ms 980 KB Output is correct
78 Correct 6 ms 1492 KB Output is correct
79 Correct 161 ms 19080 KB Output is correct
80 Correct 279 ms 29416 KB Output is correct
81 Correct 460 ms 38156 KB Output is correct
82 Incorrect 1 ms 212 KB Tree (a[0], b[0]) = (-1, -1) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4)
83 Halted 0 ms 0 KB -