Submission #441815

# Submission time Handle Problem Language Result Execution time Memory
441815 2021-07-06T09:14:59 Z baluteshih Fountain Parks (IOI21_parks) C++17
30 / 100
633 ms 48616 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define SZ(a) ((int)a.size())

pii operator+(const pii &a, const pii &b) { return pii(a.X + b.X, a.Y + b.Y); }
pii operator-(const pii &a, const pii &b) { return pii(a.X - b.X, a.Y - b.Y); }

vector<int> dt[200005];
int boss[200005], conn;
int vis[200005];
map<pii, int> id, chair;

int finds(int x) {
    if (x == boss[x]) return x;
    return boss[x] = finds(boss[x]);
}

bool Union(int x, int y) {
    x = finds(x), y = finds(y);
    if (x == y) return 0;
    boss[x] = y, --conn;
    return 1;
}

vector<int> u, v, a, b, gx, gy;

int goaway(pii p) {
    auto q = chair.find(p);
    if (q == chair.end())
        return 1;
    if (vis[q->Y])
        return 0;
    vis[q->Y] = 1;
    if (gx[u[q->Y]] == gy[v[q->Y]]) {
        pii d = q->X - pii(gx[u[q->Y]], gy[u[q->Y]]);
        d.Y *= -1;
        if (!goaway(pii(gx[u[q->Y]], gy[u[q->Y]]) + d))
            return 0;
        a[q->Y] = gx[u[q->Y]] + d.X;
        b[q->Y] = gy[u[q->Y]] + d.Y;
        chair[pii(a[q->Y], b[q->Y])] = q->Y;
    }
    else {
        pii d = q->X - pii(gx[u[q->Y]], gy[u[q->Y]]);
        d.X *= -1;
        if (!goaway(pii(gx[u[q->Y]], gy[u[q->Y]]) + d))
            return 0;
        a[q->Y] = gx[u[q->Y]] + d.X;
        b[q->Y] = gy[u[q->Y]] + d.Y;
        chair[pii(a[q->Y], b[q->Y])] = q->Y;
    }
    return 1;
}

int construct_roads(vector<int> x, vector<int> y) {
    gx = x, gy = y;
    if (x.size() == 1) {
	    build({}, {}, {}, {});
        return 1;
    }
    int n = SZ(x);
    conn = n;
    iota(boss, boss + n, 0);
    int L = *min_element(ALL(y));
    int R = *max_element(ALL(y));
    for (int i = 0; i < n; ++i) {
        dt[y[i]].pb(i);
        id[pii(x[i], y[i])] = i;
    }
    for (int i = L; i <= R; i += 2) {
        if (dt[i].empty())
            return 0;
        sort(ALL(dt[i]), [&](int p, int q){ return x[p] < x[q]; });
    }
    for (int i = L; i <= R; i += 2) {
        for (int p : dt[i]) {

            auto q = id.find(pii(x[p], y[p]) + pii(2, 0));
            if (q != id.end() && finds(p) != finds(q->Y)) {
                Union(p, q->Y);
                if (chair.find(pii(x[p], y[p]) + pii(1, -1)) == chair.end()) {
                    chair[pii(x[p], y[p]) + pii(1, -1)] = SZ(u);
                    u.pb(p), v.pb(q->Y);
                    a.pb(x[p] + 1);
                    b.pb(y[p] - 1);
                }
                else {
                    assert(goaway(pii(x[p], y[p]) + pii(1, 1)));
                    chair[pii(x[p], y[p]) + pii(1, 1)] = SZ(u);
                    u.pb(p), v.pb(q->Y);
                    a.pb(x[p] + 1);
                    b.pb(y[p] + 1);
                }
            }

            q = id.find(pii(x[p], y[p]) + pii(0, 2));
            if (q != id.end() && finds(p) != finds(q->Y)) {
                Union(p, q->Y);
                if (chair.find(pii(x[p], y[p]) + pii(-1, 1)) == chair.end()) {
                    chair[pii(x[p], y[p]) + pii(-1, 1)] = SZ(u);
                    u.pb(p), v.pb(q->Y);
                    a.pb(x[p] - 1);
                    b.pb(y[p] + 1);
                }
                else {
                    assert(goaway(pii(x[p], y[p]) + pii(1, 1)));
                    chair[pii(x[p], y[p]) + pii(1, 1)] = SZ(u);
                    u.pb(p), v.pb(q->Y);
                    a.pb(x[p] + 1);
                    b.pb(y[p] + 1);
                }
            }
        }
    }
    
    if (conn != 1)
        return 0;
    build(u, v, a, b);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4892 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 222 ms 28032 KB Output is correct
10 Correct 18 ms 7460 KB Output is correct
11 Correct 83 ms 17436 KB Output is correct
12 Correct 23 ms 8708 KB Output is correct
13 Correct 32 ms 10300 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 5 ms 5196 KB Output is correct
16 Correct 232 ms 28056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4892 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 222 ms 28032 KB Output is correct
10 Correct 18 ms 7460 KB Output is correct
11 Correct 83 ms 17436 KB Output is correct
12 Correct 23 ms 8708 KB Output is correct
13 Correct 32 ms 10300 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 5 ms 5196 KB Output is correct
16 Correct 232 ms 28056 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 543 ms 48152 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 5 ms 5324 KB Output is correct
27 Correct 6 ms 5452 KB Output is correct
28 Correct 185 ms 22260 KB Output is correct
29 Correct 306 ms 30952 KB Output is correct
30 Correct 434 ms 39524 KB Output is correct
31 Correct 580 ms 48144 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 4940 KB Output is correct
34 Correct 3 ms 4940 KB Output is correct
35 Correct 4 ms 4996 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 3 ms 4940 KB Output is correct
43 Correct 5 ms 5196 KB Output is correct
44 Correct 5 ms 5324 KB Output is correct
45 Correct 239 ms 27116 KB Output is correct
46 Correct 385 ms 37100 KB Output is correct
47 Correct 368 ms 37172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4892 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 222 ms 28032 KB Output is correct
10 Correct 18 ms 7460 KB Output is correct
11 Correct 83 ms 17436 KB Output is correct
12 Correct 23 ms 8708 KB Output is correct
13 Correct 32 ms 10300 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 5 ms 5196 KB Output is correct
16 Correct 232 ms 28056 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 543 ms 48152 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 5 ms 5324 KB Output is correct
27 Correct 6 ms 5452 KB Output is correct
28 Correct 185 ms 22260 KB Output is correct
29 Correct 306 ms 30952 KB Output is correct
30 Correct 434 ms 39524 KB Output is correct
31 Correct 580 ms 48144 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 4940 KB Output is correct
34 Correct 3 ms 4940 KB Output is correct
35 Correct 4 ms 4996 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 3 ms 4940 KB Output is correct
43 Correct 5 ms 5196 KB Output is correct
44 Correct 5 ms 5324 KB Output is correct
45 Correct 239 ms 27116 KB Output is correct
46 Correct 385 ms 37100 KB Output is correct
47 Correct 368 ms 37172 KB Output is correct
48 Correct 3 ms 4940 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 5 ms 4940 KB Output is correct
51 Correct 3 ms 4940 KB Output is correct
52 Correct 4 ms 4940 KB Output is correct
53 Correct 3 ms 4940 KB Output is correct
54 Correct 3 ms 4940 KB Output is correct
55 Correct 533 ms 47288 KB Output is correct
56 Correct 3 ms 4940 KB Output is correct
57 Correct 5 ms 5324 KB Output is correct
58 Correct 12 ms 6348 KB Output is correct
59 Correct 10 ms 6028 KB Output is correct
60 Correct 227 ms 26068 KB Output is correct
61 Correct 331 ms 33304 KB Output is correct
62 Correct 431 ms 39704 KB Output is correct
63 Correct 567 ms 47048 KB Output is correct
64 Correct 3 ms 4940 KB Output is correct
65 Correct 3 ms 4940 KB Output is correct
66 Correct 3 ms 4940 KB Output is correct
67 Correct 541 ms 48176 KB Output is correct
68 Correct 575 ms 48120 KB Output is correct
69 Correct 633 ms 47896 KB Output is correct
70 Correct 7 ms 5324 KB Output is correct
71 Correct 8 ms 5836 KB Output is correct
72 Correct 227 ms 26496 KB Output is correct
73 Correct 454 ms 37348 KB Output is correct
74 Correct 553 ms 48024 KB Output is correct
75 Correct 565 ms 47640 KB Output is correct
76 Correct 521 ms 48324 KB Output is correct
77 Correct 6 ms 5452 KB Output is correct
78 Correct 10 ms 5908 KB Output is correct
79 Correct 236 ms 26424 KB Output is correct
80 Correct 347 ms 37140 KB Output is correct
81 Correct 553 ms 47868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4892 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 222 ms 28032 KB Output is correct
10 Correct 18 ms 7460 KB Output is correct
11 Correct 83 ms 17436 KB Output is correct
12 Correct 23 ms 8708 KB Output is correct
13 Correct 32 ms 10300 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 5 ms 5196 KB Output is correct
16 Correct 232 ms 28056 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 538 ms 48616 KB Output is correct
21 Correct 472 ms 47028 KB Output is correct
22 Correct 479 ms 47032 KB Output is correct
23 Correct 423 ms 40488 KB Output is correct
24 Correct 170 ms 24112 KB Output is correct
25 Correct 182 ms 24268 KB Output is correct
26 Correct 475 ms 39812 KB Output is correct
27 Correct 571 ms 46148 KB Output is correct
28 Correct 554 ms 46116 KB Output is correct
29 Correct 556 ms 46028 KB Output is correct
30 Correct 483 ms 46020 KB Output is correct
31 Correct 3 ms 4992 KB Output is correct
32 Incorrect 29 ms 8212 KB Tree (a[158], b[158]) = (185899, 20261) is not adjacent to edge between u[158]=2246 @(185900, 20260) and v[158]=1343 @(185902, 20260)
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4892 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 222 ms 28032 KB Output is correct
10 Correct 18 ms 7460 KB Output is correct
11 Correct 83 ms 17436 KB Output is correct
12 Correct 23 ms 8708 KB Output is correct
13 Correct 32 ms 10300 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 5 ms 5196 KB Output is correct
16 Correct 232 ms 28056 KB Output is correct
17 Correct 479 ms 47640 KB Output is correct
18 Correct 547 ms 47560 KB Output is correct
19 Correct 497 ms 46892 KB Output is correct
20 Correct 546 ms 45076 KB Output is correct
21 Correct 536 ms 41396 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Incorrect 62 ms 12256 KB Tree (a[1345], b[1345]) = (185217, 20655) is not adjacent to edge between u[1345]=6338 @(185218, 20654) and v[1345]=20038 @(185220, 20654)
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4892 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 222 ms 28032 KB Output is correct
10 Correct 18 ms 7460 KB Output is correct
11 Correct 83 ms 17436 KB Output is correct
12 Correct 23 ms 8708 KB Output is correct
13 Correct 32 ms 10300 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 5 ms 5196 KB Output is correct
16 Correct 232 ms 28056 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 3 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 543 ms 48152 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 6 ms 5196 KB Output is correct
26 Correct 5 ms 5324 KB Output is correct
27 Correct 6 ms 5452 KB Output is correct
28 Correct 185 ms 22260 KB Output is correct
29 Correct 306 ms 30952 KB Output is correct
30 Correct 434 ms 39524 KB Output is correct
31 Correct 580 ms 48144 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 4940 KB Output is correct
34 Correct 3 ms 4940 KB Output is correct
35 Correct 4 ms 4996 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 3 ms 4940 KB Output is correct
43 Correct 5 ms 5196 KB Output is correct
44 Correct 5 ms 5324 KB Output is correct
45 Correct 239 ms 27116 KB Output is correct
46 Correct 385 ms 37100 KB Output is correct
47 Correct 368 ms 37172 KB Output is correct
48 Correct 3 ms 4940 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 5 ms 4940 KB Output is correct
51 Correct 3 ms 4940 KB Output is correct
52 Correct 4 ms 4940 KB Output is correct
53 Correct 3 ms 4940 KB Output is correct
54 Correct 3 ms 4940 KB Output is correct
55 Correct 533 ms 47288 KB Output is correct
56 Correct 3 ms 4940 KB Output is correct
57 Correct 5 ms 5324 KB Output is correct
58 Correct 12 ms 6348 KB Output is correct
59 Correct 10 ms 6028 KB Output is correct
60 Correct 227 ms 26068 KB Output is correct
61 Correct 331 ms 33304 KB Output is correct
62 Correct 431 ms 39704 KB Output is correct
63 Correct 567 ms 47048 KB Output is correct
64 Correct 3 ms 4940 KB Output is correct
65 Correct 3 ms 4940 KB Output is correct
66 Correct 3 ms 4940 KB Output is correct
67 Correct 541 ms 48176 KB Output is correct
68 Correct 575 ms 48120 KB Output is correct
69 Correct 633 ms 47896 KB Output is correct
70 Correct 7 ms 5324 KB Output is correct
71 Correct 8 ms 5836 KB Output is correct
72 Correct 227 ms 26496 KB Output is correct
73 Correct 454 ms 37348 KB Output is correct
74 Correct 553 ms 48024 KB Output is correct
75 Correct 565 ms 47640 KB Output is correct
76 Correct 521 ms 48324 KB Output is correct
77 Correct 6 ms 5452 KB Output is correct
78 Correct 10 ms 5908 KB Output is correct
79 Correct 236 ms 26424 KB Output is correct
80 Correct 347 ms 37140 KB Output is correct
81 Correct 553 ms 47868 KB Output is correct
82 Correct 3 ms 4940 KB Output is correct
83 Correct 3 ms 4940 KB Output is correct
84 Correct 3 ms 4940 KB Output is correct
85 Correct 538 ms 48616 KB Output is correct
86 Correct 472 ms 47028 KB Output is correct
87 Correct 479 ms 47032 KB Output is correct
88 Correct 423 ms 40488 KB Output is correct
89 Correct 170 ms 24112 KB Output is correct
90 Correct 182 ms 24268 KB Output is correct
91 Correct 475 ms 39812 KB Output is correct
92 Correct 571 ms 46148 KB Output is correct
93 Correct 554 ms 46116 KB Output is correct
94 Correct 556 ms 46028 KB Output is correct
95 Correct 483 ms 46020 KB Output is correct
96 Correct 3 ms 4992 KB Output is correct
97 Incorrect 29 ms 8212 KB Tree (a[158], b[158]) = (185899, 20261) is not adjacent to edge between u[158]=2246 @(185900, 20260) and v[158]=1343 @(185902, 20260)
98 Halted 0 ms 0 KB -