Submission #583092

# Submission time Handle Problem Language Result Execution time Memory
583092 2022-06-24T20:14:33 Z georgievskiy Fountain Parks (IOI21_parks) C++17
55 / 100
773 ms 91772 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

int n;
map<pii, int> field;
vector<int> x, y, used;
vector<pii> e;

void dfs(int v, int p) {
    if (used[v])
        return;
    if (p != -1)
        e.emplace_back(v, p);
    used[v] = 1;
    int vx = x[v], vy = y[v];
    pii t[4] = {{vx + 2, vy}, {vx - 2, vy}, {vx, vy + 2}, {vx, vy - 2}};
    for (int i = 0; i < 4; i++)
        if (field.count(t[i]))
            dfs(field[t[i]], v);
}

int construct_roads(std::vector<int> X, std::vector<int> Y) {
    n = X.size(), x = X, y = Y;
    for (int i = 0; i < n; i++)
        field[{x[i], y[i]}] = i;

    used.resize(n, 0);
    dfs(0, -1);
    if (count(used.begin(), used.end(), 0))
        return 0;

    vector<int> us, vs;
    set<pii> loc;

    for (int i = 0; i < e.size(); i++) {
        us.push_back(e[i].first), vs.push_back(e[i].second);
        pii p = e[i];
        pii mid = {(x[p.first] + x[p.second]) / 2, (y[p.first] + y[p.second]) / 2};
        field[mid] = i;
        if (x[p.first] == x[p.second]) {
            loc.insert({mid.first-1, mid.second});
            loc.insert({mid.first+1, mid.second});
        } else {
            loc.insert({mid.first, mid.second+1});
            loc.insert({mid.first, mid.second-1});
        }
    }

    vector<int> a(e.size(), -1), b(e.size());

    if (*max_element(x.begin(), x.end()) <= 4) {

        for (pii p : loc) {
            if (p.first == 1) {
                pii p1 = p;
                p1.first++;
                if (field.count(p1)) {
                    a[field[p1]] = p.first, b[field[p1]] = p.second;
                    field.erase(p1);
                }
            } else if (p.first == 5) {
                pii p1 = p;
                p1.first--;
                if (field.count(p1)) {
                    a[field[p1]] = p.first, b[field[p1]] = p.second;
                    field.erase(p1);
                }
            } else {
                pii p1 = p, p2 = p;
                p1.second++, p2.second--;
                if (field.count(p1)) {
                    a[field[p1]] = p.first, b[field[p1]] = p.second;
                    field.erase(p1);
                } else if (field.count(p2)) {
                    a[field[p2]] = p.first, b[field[p2]] = p.second;
                    field.erase(p2);
                }
            }
        }

    } else
    for (pii p : loc) {
        pii p1 = p, p2 = p;
        if ((p.first / 2 + p.second / 2) % 2)
            p1.first++, p2.first--;
        else
            p1.second++, p2.second--;

        if (field.count(p1)) {
            a[field[p1]] = p.first, b[field[p1]] = p.second;
            field.erase(p1);
        } else if (field.count(p2)) {
            a[field[p2]] = p.first, b[field[p2]] = p.second;
            field.erase(p2);
        }
    }

    if (count(a.begin(), a.end(), -1))
        return 0;

    build(us, vs, a, b);

    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 0; i < e.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 272 ms 44752 KB Output is correct
10 Correct 32 ms 4820 KB Output is correct
11 Correct 161 ms 24836 KB Output is correct
12 Correct 33 ms 7084 KB Output is correct
13 Correct 34 ms 8836 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 295 ms 38832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 272 ms 44752 KB Output is correct
10 Correct 32 ms 4820 KB Output is correct
11 Correct 161 ms 24836 KB Output is correct
12 Correct 33 ms 7084 KB Output is correct
13 Correct 34 ms 8836 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 295 ms 38832 KB Output is correct
17 Correct 0 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 695 ms 80684 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 700 KB Output is correct
28 Correct 216 ms 33228 KB Output is correct
29 Correct 384 ms 46336 KB Output is correct
30 Correct 490 ms 65168 KB Output is correct
31 Correct 606 ms 77908 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 568 KB Output is correct
45 Correct 283 ms 38428 KB Output is correct
46 Correct 391 ms 56352 KB Output is correct
47 Correct 406 ms 55500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 272 ms 44752 KB Output is correct
10 Correct 32 ms 4820 KB Output is correct
11 Correct 161 ms 24836 KB Output is correct
12 Correct 33 ms 7084 KB Output is correct
13 Correct 34 ms 8836 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 295 ms 38832 KB Output is correct
17 Correct 0 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 695 ms 80684 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 700 KB Output is correct
28 Correct 216 ms 33228 KB Output is correct
29 Correct 384 ms 46336 KB Output is correct
30 Correct 490 ms 65168 KB Output is correct
31 Correct 606 ms 77908 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 568 KB Output is correct
45 Correct 283 ms 38428 KB Output is correct
46 Correct 391 ms 56352 KB Output is correct
47 Correct 406 ms 55500 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 272 ms 44752 KB Output is correct
10 Correct 32 ms 4820 KB Output is correct
11 Correct 161 ms 24836 KB Output is correct
12 Correct 33 ms 7084 KB Output is correct
13 Correct 34 ms 8836 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 295 ms 38832 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 544 ms 82200 KB Output is correct
21 Correct 607 ms 76596 KB Output is correct
22 Correct 635 ms 73456 KB Output is correct
23 Correct 508 ms 69580 KB Output is correct
24 Correct 149 ms 18304 KB Output is correct
25 Correct 142 ms 18336 KB Output is correct
26 Correct 135 ms 18328 KB Output is correct
27 Correct 561 ms 63352 KB Output is correct
28 Correct 519 ms 63292 KB Output is correct
29 Correct 758 ms 63428 KB Output is correct
30 Correct 773 ms 63364 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 35 ms 5192 KB Output is correct
33 Correct 57 ms 9164 KB Output is correct
34 Correct 536 ms 77728 KB Output is correct
35 Correct 7 ms 1236 KB Output is correct
36 Correct 29 ms 4912 KB Output is correct
37 Correct 72 ms 9496 KB Output is correct
38 Correct 230 ms 22840 KB Output is correct
39 Correct 322 ms 31104 KB Output is correct
40 Correct 424 ms 39668 KB Output is correct
41 Correct 514 ms 48320 KB Output is correct
42 Correct 644 ms 56756 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 596 KB Output is correct
55 Correct 2 ms 596 KB Output is correct
56 Correct 252 ms 37508 KB Output is correct
57 Correct 384 ms 55128 KB Output is correct
58 Correct 395 ms 54264 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 615 ms 83276 KB Output is correct
63 Correct 610 ms 83844 KB Output is correct
64 Correct 622 ms 86492 KB Output is correct
65 Correct 3 ms 724 KB Output is correct
66 Correct 5 ms 1108 KB Output is correct
67 Correct 290 ms 33168 KB Output is correct
68 Correct 466 ms 53368 KB Output is correct
69 Correct 650 ms 66696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 272 ms 44752 KB Output is correct
10 Correct 32 ms 4820 KB Output is correct
11 Correct 161 ms 24836 KB Output is correct
12 Correct 33 ms 7084 KB Output is correct
13 Correct 34 ms 8836 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 295 ms 38832 KB Output is correct
17 Correct 627 ms 91772 KB Output is correct
18 Correct 605 ms 80684 KB Output is correct
19 Correct 574 ms 82704 KB Output is correct
20 Correct 726 ms 71840 KB Output is correct
21 Correct 594 ms 64020 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 77 ms 10336 KB Output is correct
24 Correct 14 ms 2900 KB Output is correct
25 Correct 44 ms 7368 KB Output is correct
26 Correct 79 ms 11860 KB Output is correct
27 Correct 327 ms 34812 KB Output is correct
28 Correct 411 ms 43516 KB Output is correct
29 Correct 534 ms 52720 KB Output is correct
30 Correct 596 ms 61052 KB Output is correct
31 Correct 698 ms 69672 KB Output is correct
32 Correct 659 ms 79648 KB Output is correct
33 Correct 582 ms 91452 KB Output is correct
34 Correct 4 ms 980 KB Output is correct
35 Correct 5 ms 1492 KB Output is correct
36 Correct 279 ms 35888 KB Output is correct
37 Correct 457 ms 54832 KB Output is correct
38 Correct 653 ms 73504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 272 ms 44752 KB Output is correct
10 Correct 32 ms 4820 KB Output is correct
11 Correct 161 ms 24836 KB Output is correct
12 Correct 33 ms 7084 KB Output is correct
13 Correct 34 ms 8836 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 295 ms 38832 KB Output is correct
17 Correct 0 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 695 ms 80684 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 3 ms 700 KB Output is correct
28 Correct 216 ms 33228 KB Output is correct
29 Correct 384 ms 46336 KB Output is correct
30 Correct 490 ms 65168 KB Output is correct
31 Correct 606 ms 77908 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 2 ms 568 KB Output is correct
45 Correct 283 ms 38428 KB Output is correct
46 Correct 391 ms 56352 KB Output is correct
47 Correct 406 ms 55500 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Incorrect 1 ms 212 KB Solution announced impossible, but it is possible.
50 Halted 0 ms 0 KB -