Submission #932630

# Submission time Handle Problem Language Result Execution time Memory
932630 2024-02-24T01:18:57 Z Programmer123 Fountain Parks (IOI21_parks) C++17
15 / 100
201 ms 52148 KB
#include <bits/stdc++.h>
#include "parks.h"

std::unordered_map<int, int> map[200001];

int construct_roads(std::vector<int> x, std::vector<int> y) {
    int N = (int) x.size();
    if (N == 1) {
        build({}, {}, {}, {});
        return 1;
    }
    int maxx = x[0];
    int minx = x[0];
    for (int i = 0; i < N; ++i) {
        maxx = std::max(maxx, x[i]);
        minx = std::min(minx, x[i]);
    }
    std::vector<int> u, v, a, b;
    for (int i = 0; i < N; ++i) {
        map[x[i]][y[i]] = i;
    }
    bool seen[N];
    for (int i = 0; i < N; ++i) {
        seen[i] = false;
    }
    std::queue<int> bfs;
    bfs.push(0);
    seen[0] = true;
    auto add = [&](int x, int y, std::vector<int> &data) {
        if (x < 0 || x > 200000) return;
        if (map[x].count(y)) data.push_back(map[x][y]);
    };
    auto edges = [&](int x, int y) {
        std::vector<int> result;
        add(x, y + 2, result);
        add(x, y - 2, result);
        add(x + 2, y, result);
        add(x - 2, y, result);
        return result;
    };
    int rem = N - 1;
    while (!bfs.empty()) {
        auto next = bfs.front();
        bfs.pop();
        for (auto n: edges(x[next], y[next])) {
            if (!seen[n]) {
                seen[n] = true;
                bfs.push(n);
                rem--;
                u.push_back(next);
                v.push_back(n);
            }
        }
    }
    if (rem)
        return 0;

    std::function<std::vector<std::pair<int, int>>(int, int)> valid = [&x, &y, minx, maxx](int u,
                                                                                           int v) -> std::vector<std::pair<int, int>> {
        if (x[u] == x[v]) {
            int _y = (y[u] + y[v]) / 2;
            if (x[u] == minx) return {{minx - 1, _y}};
            if (x[u] == maxx) return {{maxx + 1, _y}};
            return {{x[u] + 1, _y},
                    {x[u] - 1, _y}};
        } else {
            int _x = (x[u] + x[v]) / 2;
            return {{_x, y[u] + 1},
                    {_x, y[u] - 1}};
        }
    };
    std::vector<std::pair<int, int>> vld[N - 1];
    for (int i = 0; i < N - 1; ++i) {
        vld[i] = valid(u[i], v[i]);
        a.push_back(vld[i][0].first);
        b.push_back(vld[i][0].second);
    }
    build(u, v, a, b);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 2 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 3 ms 11356 KB Output is correct
6 Correct 3 ms 11356 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 68 ms 29108 KB Output is correct
10 Correct 11 ms 13400 KB Output is correct
11 Correct 33 ms 20668 KB Output is correct
12 Correct 11 ms 13916 KB Output is correct
13 Correct 13 ms 14444 KB Output is correct
14 Correct 3 ms 11356 KB Output is correct
15 Correct 3 ms 11356 KB Output is correct
16 Correct 68 ms 29044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 2 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 3 ms 11356 KB Output is correct
6 Correct 3 ms 11356 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 68 ms 29108 KB Output is correct
10 Correct 11 ms 13400 KB Output is correct
11 Correct 33 ms 20668 KB Output is correct
12 Correct 11 ms 13916 KB Output is correct
13 Correct 13 ms 14444 KB Output is correct
14 Correct 3 ms 11356 KB Output is correct
15 Correct 3 ms 11356 KB Output is correct
16 Correct 68 ms 29044 KB Output is correct
17 Correct 3 ms 11356 KB Output is correct
18 Correct 3 ms 11356 KB Output is correct
19 Correct 3 ms 11356 KB Output is correct
20 Correct 3 ms 11356 KB Output is correct
21 Correct 3 ms 11552 KB Output is correct
22 Correct 3 ms 11356 KB Output is correct
23 Correct 143 ms 45552 KB Output is correct
24 Correct 5 ms 11356 KB Output is correct
25 Correct 3 ms 11612 KB Output is correct
26 Correct 5 ms 11612 KB Output is correct
27 Correct 4 ms 11612 KB Output is correct
28 Correct 56 ms 24672 KB Output is correct
29 Correct 85 ms 31700 KB Output is correct
30 Correct 114 ms 38000 KB Output is correct
31 Correct 158 ms 45712 KB Output is correct
32 Correct 3 ms 11356 KB Output is correct
33 Correct 3 ms 11356 KB Output is correct
34 Correct 3 ms 11352 KB Output is correct
35 Correct 3 ms 11356 KB Output is correct
36 Correct 3 ms 11356 KB Output is correct
37 Correct 3 ms 11356 KB Output is correct
38 Correct 3 ms 11356 KB Output is correct
39 Correct 3 ms 11360 KB Output is correct
40 Correct 3 ms 11356 KB Output is correct
41 Correct 3 ms 11356 KB Output is correct
42 Correct 4 ms 11768 KB Output is correct
43 Correct 4 ms 11416 KB Output is correct
44 Correct 4 ms 11612 KB Output is correct
45 Correct 70 ms 28528 KB Output is correct
46 Correct 107 ms 35592 KB Output is correct
47 Correct 107 ms 35440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 2 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 3 ms 11356 KB Output is correct
6 Correct 3 ms 11356 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 68 ms 29108 KB Output is correct
10 Correct 11 ms 13400 KB Output is correct
11 Correct 33 ms 20668 KB Output is correct
12 Correct 11 ms 13916 KB Output is correct
13 Correct 13 ms 14444 KB Output is correct
14 Correct 3 ms 11356 KB Output is correct
15 Correct 3 ms 11356 KB Output is correct
16 Correct 68 ms 29044 KB Output is correct
17 Correct 3 ms 11356 KB Output is correct
18 Correct 3 ms 11356 KB Output is correct
19 Correct 3 ms 11356 KB Output is correct
20 Correct 3 ms 11356 KB Output is correct
21 Correct 3 ms 11552 KB Output is correct
22 Correct 3 ms 11356 KB Output is correct
23 Correct 143 ms 45552 KB Output is correct
24 Correct 5 ms 11356 KB Output is correct
25 Correct 3 ms 11612 KB Output is correct
26 Correct 5 ms 11612 KB Output is correct
27 Correct 4 ms 11612 KB Output is correct
28 Correct 56 ms 24672 KB Output is correct
29 Correct 85 ms 31700 KB Output is correct
30 Correct 114 ms 38000 KB Output is correct
31 Correct 158 ms 45712 KB Output is correct
32 Correct 3 ms 11356 KB Output is correct
33 Correct 3 ms 11356 KB Output is correct
34 Correct 3 ms 11352 KB Output is correct
35 Correct 3 ms 11356 KB Output is correct
36 Correct 3 ms 11356 KB Output is correct
37 Correct 3 ms 11356 KB Output is correct
38 Correct 3 ms 11356 KB Output is correct
39 Correct 3 ms 11360 KB Output is correct
40 Correct 3 ms 11356 KB Output is correct
41 Correct 3 ms 11356 KB Output is correct
42 Correct 4 ms 11768 KB Output is correct
43 Correct 4 ms 11416 KB Output is correct
44 Correct 4 ms 11612 KB Output is correct
45 Correct 70 ms 28528 KB Output is correct
46 Correct 107 ms 35592 KB Output is correct
47 Correct 107 ms 35440 KB Output is correct
48 Correct 3 ms 11356 KB Output is correct
49 Correct 3 ms 11356 KB Output is correct
50 Correct 3 ms 11356 KB Output is correct
51 Correct 3 ms 11356 KB Output is correct
52 Incorrect 3 ms 11356 KB Tree @(5, 7) appears more than once: for edges on positions 4 and 5
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 2 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 3 ms 11356 KB Output is correct
6 Correct 3 ms 11356 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 68 ms 29108 KB Output is correct
10 Correct 11 ms 13400 KB Output is correct
11 Correct 33 ms 20668 KB Output is correct
12 Correct 11 ms 13916 KB Output is correct
13 Correct 13 ms 14444 KB Output is correct
14 Correct 3 ms 11356 KB Output is correct
15 Correct 3 ms 11356 KB Output is correct
16 Correct 68 ms 29044 KB Output is correct
17 Correct 3 ms 11352 KB Output is correct
18 Correct 3 ms 11352 KB Output is correct
19 Correct 3 ms 11356 KB Output is correct
20 Incorrect 201 ms 52148 KB Tree @(195233, 4771) appears more than once: for edges on positions 0 and 2
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 2 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 3 ms 11356 KB Output is correct
6 Correct 3 ms 11356 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 68 ms 29108 KB Output is correct
10 Correct 11 ms 13400 KB Output is correct
11 Correct 33 ms 20668 KB Output is correct
12 Correct 11 ms 13916 KB Output is correct
13 Correct 13 ms 14444 KB Output is correct
14 Correct 3 ms 11356 KB Output is correct
15 Correct 3 ms 11356 KB Output is correct
16 Correct 68 ms 29044 KB Output is correct
17 Correct 189 ms 48032 KB Output is correct
18 Incorrect 185 ms 50560 KB Tree @(50003, 50003) appears more than once: for edges on positions 39328 and 39330
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11608 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 2 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 3 ms 11356 KB Output is correct
6 Correct 3 ms 11356 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 68 ms 29108 KB Output is correct
10 Correct 11 ms 13400 KB Output is correct
11 Correct 33 ms 20668 KB Output is correct
12 Correct 11 ms 13916 KB Output is correct
13 Correct 13 ms 14444 KB Output is correct
14 Correct 3 ms 11356 KB Output is correct
15 Correct 3 ms 11356 KB Output is correct
16 Correct 68 ms 29044 KB Output is correct
17 Correct 3 ms 11356 KB Output is correct
18 Correct 3 ms 11356 KB Output is correct
19 Correct 3 ms 11356 KB Output is correct
20 Correct 3 ms 11356 KB Output is correct
21 Correct 3 ms 11552 KB Output is correct
22 Correct 3 ms 11356 KB Output is correct
23 Correct 143 ms 45552 KB Output is correct
24 Correct 5 ms 11356 KB Output is correct
25 Correct 3 ms 11612 KB Output is correct
26 Correct 5 ms 11612 KB Output is correct
27 Correct 4 ms 11612 KB Output is correct
28 Correct 56 ms 24672 KB Output is correct
29 Correct 85 ms 31700 KB Output is correct
30 Correct 114 ms 38000 KB Output is correct
31 Correct 158 ms 45712 KB Output is correct
32 Correct 3 ms 11356 KB Output is correct
33 Correct 3 ms 11356 KB Output is correct
34 Correct 3 ms 11352 KB Output is correct
35 Correct 3 ms 11356 KB Output is correct
36 Correct 3 ms 11356 KB Output is correct
37 Correct 3 ms 11356 KB Output is correct
38 Correct 3 ms 11356 KB Output is correct
39 Correct 3 ms 11360 KB Output is correct
40 Correct 3 ms 11356 KB Output is correct
41 Correct 3 ms 11356 KB Output is correct
42 Correct 4 ms 11768 KB Output is correct
43 Correct 4 ms 11416 KB Output is correct
44 Correct 4 ms 11612 KB Output is correct
45 Correct 70 ms 28528 KB Output is correct
46 Correct 107 ms 35592 KB Output is correct
47 Correct 107 ms 35440 KB Output is correct
48 Correct 3 ms 11356 KB Output is correct
49 Correct 3 ms 11356 KB Output is correct
50 Correct 3 ms 11356 KB Output is correct
51 Correct 3 ms 11356 KB Output is correct
52 Incorrect 3 ms 11356 KB Tree @(5, 7) appears more than once: for edges on positions 4 and 5
53 Halted 0 ms 0 KB -