Submission #441811

# Submission time Handle Problem Language Result Execution time Memory
441811 2021-07-06T08:44:27 Z baluteshih Fountain Parks (IOI21_parks) C++17
30 / 100
574 ms 48992 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); }

vector<int> dt[200005];
int boss[200005], conn;
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;
}

int construct_roads(vector<int> x, vector<int> 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]; });
    }
    vector<int> u, v, a, b;
    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(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);
                }
            }

            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(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);
                }
            }
        }
    }
    
    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 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 217 ms 27364 KB Output is correct
10 Correct 17 ms 7372 KB Output is correct
11 Correct 82 ms 16952 KB Output is correct
12 Correct 23 ms 8572 KB Output is correct
13 Correct 24 ms 9964 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 209 ms 27296 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 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 217 ms 27364 KB Output is correct
10 Correct 17 ms 7372 KB Output is correct
11 Correct 82 ms 16952 KB Output is correct
12 Correct 23 ms 8572 KB Output is correct
13 Correct 24 ms 9964 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 209 ms 27296 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 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 543 ms 48076 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5196 KB Output is correct
27 Correct 5 ms 5320 KB Output is correct
28 Correct 159 ms 22224 KB Output is correct
29 Correct 261 ms 30888 KB Output is correct
30 Correct 381 ms 39480 KB Output is correct
31 Correct 505 ms 48304 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 3 ms 5000 KB Output is correct
35 Correct 3 ms 4940 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 3 ms 4940 KB Output is correct
42 Correct 3 ms 4992 KB Output is correct
43 Correct 4 ms 5196 KB Output is correct
44 Correct 5 ms 5324 KB Output is correct
45 Correct 211 ms 27112 KB Output is correct
46 Correct 341 ms 37172 KB Output is correct
47 Correct 325 ms 37144 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 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 217 ms 27364 KB Output is correct
10 Correct 17 ms 7372 KB Output is correct
11 Correct 82 ms 16952 KB Output is correct
12 Correct 23 ms 8572 KB Output is correct
13 Correct 24 ms 9964 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 209 ms 27296 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 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 543 ms 48076 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5196 KB Output is correct
27 Correct 5 ms 5320 KB Output is correct
28 Correct 159 ms 22224 KB Output is correct
29 Correct 261 ms 30888 KB Output is correct
30 Correct 381 ms 39480 KB Output is correct
31 Correct 505 ms 48304 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 3 ms 5000 KB Output is correct
35 Correct 3 ms 4940 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 3 ms 4940 KB Output is correct
42 Correct 3 ms 4992 KB Output is correct
43 Correct 4 ms 5196 KB Output is correct
44 Correct 5 ms 5324 KB Output is correct
45 Correct 211 ms 27112 KB Output is correct
46 Correct 341 ms 37172 KB Output is correct
47 Correct 325 ms 37144 KB Output is correct
48 Correct 3 ms 4940 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 3 ms 4940 KB Output is correct
51 Correct 3 ms 4992 KB Output is correct
52 Correct 3 ms 4940 KB Output is correct
53 Correct 4 ms 5000 KB Output is correct
54 Correct 3 ms 4940 KB Output is correct
55 Correct 496 ms 46948 KB Output is correct
56 Correct 3 ms 4940 KB Output is correct
57 Correct 6 ms 5324 KB Output is correct
58 Correct 12 ms 6348 KB Output is correct
59 Correct 9 ms 5964 KB Output is correct
60 Correct 213 ms 26040 KB Output is correct
61 Correct 306 ms 33348 KB Output is correct
62 Correct 403 ms 39832 KB Output is correct
63 Correct 501 ms 47272 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 511 ms 48104 KB Output is correct
68 Correct 507 ms 48236 KB Output is correct
69 Correct 495 ms 47896 KB Output is correct
70 Correct 5 ms 5324 KB Output is correct
71 Correct 8 ms 5772 KB Output is correct
72 Correct 211 ms 26368 KB Output is correct
73 Correct 357 ms 37240 KB Output is correct
74 Correct 514 ms 48068 KB Output is correct
75 Correct 490 ms 47472 KB Output is correct
76 Correct 531 ms 48260 KB Output is correct
77 Correct 6 ms 5452 KB Output is correct
78 Correct 8 ms 5836 KB Output is correct
79 Correct 219 ms 26296 KB Output is correct
80 Correct 361 ms 37252 KB Output is correct
81 Correct 524 ms 47908 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 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 217 ms 27364 KB Output is correct
10 Correct 17 ms 7372 KB Output is correct
11 Correct 82 ms 16952 KB Output is correct
12 Correct 23 ms 8572 KB Output is correct
13 Correct 24 ms 9964 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 209 ms 27296 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 533 ms 48992 KB Output is correct
21 Correct 480 ms 47256 KB Output is correct
22 Correct 468 ms 47272 KB Output is correct
23 Correct 374 ms 40692 KB Output is correct
24 Correct 163 ms 24132 KB Output is correct
25 Correct 172 ms 24056 KB Output is correct
26 Correct 441 ms 39716 KB Output is correct
27 Correct 574 ms 45976 KB Output is correct
28 Correct 535 ms 46272 KB Output is correct
29 Correct 511 ms 45852 KB Output is correct
30 Correct 486 ms 45840 KB Output is correct
31 Correct 3 ms 4940 KB Output is correct
32 Runtime error 18 ms 12640 KB Execution killed with signal 6
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 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 217 ms 27364 KB Output is correct
10 Correct 17 ms 7372 KB Output is correct
11 Correct 82 ms 16952 KB Output is correct
12 Correct 23 ms 8572 KB Output is correct
13 Correct 24 ms 9964 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 209 ms 27296 KB Output is correct
17 Correct 475 ms 45892 KB Output is correct
18 Correct 446 ms 47996 KB Output is correct
19 Correct 478 ms 47256 KB Output is correct
20 Correct 522 ms 45208 KB Output is correct
21 Correct 454 ms 41304 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Runtime error 29 ms 16172 KB Execution killed with signal 6
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 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 217 ms 27364 KB Output is correct
10 Correct 17 ms 7372 KB Output is correct
11 Correct 82 ms 16952 KB Output is correct
12 Correct 23 ms 8572 KB Output is correct
13 Correct 24 ms 9964 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
15 Correct 4 ms 5196 KB Output is correct
16 Correct 209 ms 27296 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 3 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 543 ms 48076 KB Output is correct
24 Correct 3 ms 4940 KB Output is correct
25 Correct 4 ms 5196 KB Output is correct
26 Correct 4 ms 5196 KB Output is correct
27 Correct 5 ms 5320 KB Output is correct
28 Correct 159 ms 22224 KB Output is correct
29 Correct 261 ms 30888 KB Output is correct
30 Correct 381 ms 39480 KB Output is correct
31 Correct 505 ms 48304 KB Output is correct
32 Correct 3 ms 4940 KB Output is correct
33 Correct 3 ms 4940 KB Output is correct
34 Correct 3 ms 5000 KB Output is correct
35 Correct 3 ms 4940 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 3 ms 4940 KB Output is correct
42 Correct 3 ms 4992 KB Output is correct
43 Correct 4 ms 5196 KB Output is correct
44 Correct 5 ms 5324 KB Output is correct
45 Correct 211 ms 27112 KB Output is correct
46 Correct 341 ms 37172 KB Output is correct
47 Correct 325 ms 37144 KB Output is correct
48 Correct 3 ms 4940 KB Output is correct
49 Correct 3 ms 4940 KB Output is correct
50 Correct 3 ms 4940 KB Output is correct
51 Correct 3 ms 4992 KB Output is correct
52 Correct 3 ms 4940 KB Output is correct
53 Correct 4 ms 5000 KB Output is correct
54 Correct 3 ms 4940 KB Output is correct
55 Correct 496 ms 46948 KB Output is correct
56 Correct 3 ms 4940 KB Output is correct
57 Correct 6 ms 5324 KB Output is correct
58 Correct 12 ms 6348 KB Output is correct
59 Correct 9 ms 5964 KB Output is correct
60 Correct 213 ms 26040 KB Output is correct
61 Correct 306 ms 33348 KB Output is correct
62 Correct 403 ms 39832 KB Output is correct
63 Correct 501 ms 47272 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 511 ms 48104 KB Output is correct
68 Correct 507 ms 48236 KB Output is correct
69 Correct 495 ms 47896 KB Output is correct
70 Correct 5 ms 5324 KB Output is correct
71 Correct 8 ms 5772 KB Output is correct
72 Correct 211 ms 26368 KB Output is correct
73 Correct 357 ms 37240 KB Output is correct
74 Correct 514 ms 48068 KB Output is correct
75 Correct 490 ms 47472 KB Output is correct
76 Correct 531 ms 48260 KB Output is correct
77 Correct 6 ms 5452 KB Output is correct
78 Correct 8 ms 5836 KB Output is correct
79 Correct 219 ms 26296 KB Output is correct
80 Correct 361 ms 37252 KB Output is correct
81 Correct 524 ms 47908 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 533 ms 48992 KB Output is correct
86 Correct 480 ms 47256 KB Output is correct
87 Correct 468 ms 47272 KB Output is correct
88 Correct 374 ms 40692 KB Output is correct
89 Correct 163 ms 24132 KB Output is correct
90 Correct 172 ms 24056 KB Output is correct
91 Correct 441 ms 39716 KB Output is correct
92 Correct 574 ms 45976 KB Output is correct
93 Correct 535 ms 46272 KB Output is correct
94 Correct 511 ms 45852 KB Output is correct
95 Correct 486 ms 45840 KB Output is correct
96 Correct 3 ms 4940 KB Output is correct
97 Runtime error 18 ms 12640 KB Execution killed with signal 6
98 Halted 0 ms 0 KB -