Submission #593995

# Submission time Handle Problem Language Result Execution time Memory
593995 2022-07-11T20:43:41 Z SlavicG Fountain Parks (IOI21_parks) C++17
45 / 100
385 ms 34912 KB
#include "parks.h"
#include "bits/stdc++.h"
using namespace std;

#define         sz(a)     (int)a.size()
#define        all(a)     a.begin(),a.end()
#define    forn(i, n)     for(int i = 0; i < n; ++i)

const int N = 2e5 + 10;
int p[N];
int get(int a) {
    return p[a] = (a == p[a] ? a : get(p[a]));
}
bool uni(int a, int b) {
    a = get(a), b = get(b);
    if(a == b) return false;
    p[a] = b;
    return true;
}

struct point {
    int x, y, idx;
};
bool cmp(point a, point b) {
    if(a.x < b.x) return 1;
    if(a.x > b.x) return 0;
    return a.y < b.y;
}
map<pair<int, int>, int> st;
int construct_roads(vector<int> x, vector<int> y) {
    forn(i, N) p[i] = i;
    if (x.size() == 1) {
        build({}, {}, {}, {});
        return 1;
    }
    vector<int> u, v, a, b;
    vector<point> points;
    forn(i, sz(x)) points.push_back({x[i], y[i], i}), st[{x[i], y[i]}] = i;
    sort(all(points), cmp);

    for(auto p: points) {
        pair<int, int> c = {p.x - 2, p.y};
        if(st.count(c) && uni(st[c], p.idx)) {
            u.push_back(st[c]), v.push_back(p.idx);
            if(p.x % 4 == 0) {
                if(p.y % 4 == 2) {
                    a.push_back(p.x - 1);
                    b.push_back(p.y - 1);
                } else {
                    a.push_back(p.x - 1);
                    b.push_back(p.y + 1);
                }
            } else {
                if(p.y % 4 == 2) {
                    a.push_back(p.x - 1);
                    b.push_back(p.y + 1);
                } else {
                    a.push_back(p.x - 1);
                    b.push_back(p.y - 1);
                }
            }
        }
        c = {p.x, p.y - 2};
        if(st.count(c) && uni(st[c], p.idx)) {
            u.push_back(st[c]), v.push_back(p.idx);
            if(p.y % 4 == 0) {
                if(p.x % 4 == 2) {
                    a.push_back(p.x + 1);
                    b.push_back(p.y - 1);
                } else {
                    a.push_back(p.x - 1);
                    b.push_back(p.y - 1);
                }
            } else {
                if(p.x % 4 == 2) {
                    a.push_back(p.x - 1);
                    b.push_back(p.y - 1);
                } else {
                    a.push_back(p.x + 1);
                    b.push_back(p.y - 1);
                }
            }
        }
    }
    for(int i = 0; i < sz(x); ++i) if(get(i) != get(0)) return 0;
    build(u, v, a, b);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1076 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 159 ms 17028 KB Output is correct
10 Correct 10 ms 2780 KB Output is correct
11 Correct 58 ms 9640 KB Output is correct
12 Correct 14 ms 3492 KB Output is correct
13 Correct 35 ms 7044 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1216 KB Output is correct
16 Correct 119 ms 16620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1076 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 159 ms 17028 KB Output is correct
10 Correct 10 ms 2780 KB Output is correct
11 Correct 58 ms 9640 KB Output is correct
12 Correct 14 ms 3492 KB Output is correct
13 Correct 35 ms 7044 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1216 KB Output is correct
16 Correct 119 ms 16620 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Incorrect 1 ms 980 KB Tree @(3, 5) appears more than once: for edges on positions 1 and 2
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1076 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 159 ms 17028 KB Output is correct
10 Correct 10 ms 2780 KB Output is correct
11 Correct 58 ms 9640 KB Output is correct
12 Correct 14 ms 3492 KB Output is correct
13 Correct 35 ms 7044 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1216 KB Output is correct
16 Correct 119 ms 16620 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Incorrect 1 ms 980 KB Tree @(3, 5) appears more than once: for edges on positions 1 and 2
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1076 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 159 ms 17028 KB Output is correct
10 Correct 10 ms 2780 KB Output is correct
11 Correct 58 ms 9640 KB Output is correct
12 Correct 14 ms 3492 KB Output is correct
13 Correct 35 ms 7044 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1216 KB Output is correct
16 Correct 119 ms 16620 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1072 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 315 ms 33720 KB Output is correct
21 Correct 363 ms 33096 KB Output is correct
22 Correct 385 ms 32752 KB Output is correct
23 Correct 254 ms 28524 KB Output is correct
24 Correct 214 ms 20732 KB Output is correct
25 Correct 260 ms 26128 KB Output is correct
26 Correct 211 ms 26088 KB Output is correct
27 Correct 291 ms 31112 KB Output is correct
28 Correct 321 ms 31148 KB Output is correct
29 Correct 335 ms 31100 KB Output is correct
30 Correct 370 ms 31152 KB Output is correct
31 Correct 1 ms 1080 KB Output is correct
32 Correct 20 ms 3304 KB Output is correct
33 Correct 100 ms 11240 KB Output is correct
34 Correct 334 ms 34912 KB Output is correct
35 Correct 10 ms 2356 KB Output is correct
36 Correct 64 ms 7488 KB Output is correct
37 Correct 114 ms 14012 KB Output is correct
38 Correct 111 ms 14136 KB Output is correct
39 Correct 171 ms 18316 KB Output is correct
40 Correct 204 ms 24284 KB Output is correct
41 Correct 243 ms 28652 KB Output is correct
42 Correct 318 ms 32948 KB Output is correct
43 Correct 1 ms 980 KB Output is correct
44 Correct 1 ms 980 KB Output is correct
45 Correct 1 ms 980 KB Output is correct
46 Correct 1 ms 980 KB Output is correct
47 Correct 1 ms 980 KB Output is correct
48 Correct 1 ms 980 KB Output is correct
49 Correct 1 ms 980 KB Output is correct
50 Correct 1 ms 980 KB Output is correct
51 Correct 1 ms 980 KB Output is correct
52 Correct 1 ms 980 KB Output is correct
53 Correct 1 ms 980 KB Output is correct
54 Correct 2 ms 1220 KB Output is correct
55 Correct 3 ms 1364 KB Output is correct
56 Correct 123 ms 16328 KB Output is correct
57 Correct 223 ms 24240 KB Output is correct
58 Correct 191 ms 23904 KB Output is correct
59 Correct 1 ms 980 KB Output is correct
60 Correct 1 ms 980 KB Output is correct
61 Correct 1 ms 980 KB Output is correct
62 Correct 329 ms 31964 KB Output is correct
63 Correct 276 ms 32316 KB Output is correct
64 Correct 283 ms 31632 KB Output is correct
65 Correct 3 ms 1492 KB Output is correct
66 Correct 6 ms 2068 KB Output is correct
67 Correct 141 ms 16112 KB Output is correct
68 Correct 207 ms 24896 KB Output is correct
69 Correct 337 ms 31556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1076 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 159 ms 17028 KB Output is correct
10 Correct 10 ms 2780 KB Output is correct
11 Correct 58 ms 9640 KB Output is correct
12 Correct 14 ms 3492 KB Output is correct
13 Correct 35 ms 7044 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1216 KB Output is correct
16 Correct 119 ms 16620 KB Output is correct
17 Correct 315 ms 32848 KB Output is correct
18 Correct 303 ms 33316 KB Output is correct
19 Correct 314 ms 33068 KB Output is correct
20 Correct 297 ms 30476 KB Output is correct
21 Correct 272 ms 27852 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 38 ms 6140 KB Output is correct
24 Correct 20 ms 3652 KB Output is correct
25 Correct 73 ms 10624 KB Output is correct
26 Correct 133 ms 16256 KB Output is correct
27 Correct 168 ms 16920 KB Output is correct
28 Correct 183 ms 20824 KB Output is correct
29 Correct 216 ms 25988 KB Output is correct
30 Correct 311 ms 29052 KB Output is correct
31 Correct 330 ms 32992 KB Output is correct
32 Correct 292 ms 32228 KB Output is correct
33 Correct 288 ms 32424 KB Output is correct
34 Correct 4 ms 1748 KB Output is correct
35 Correct 7 ms 2244 KB Output is correct
36 Correct 128 ms 15984 KB Output is correct
37 Correct 265 ms 24576 KB Output is correct
38 Correct 291 ms 31596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1076 KB Output is correct
3 Correct 1 ms 1080 KB Output is correct
4 Correct 1 ms 992 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 159 ms 17028 KB Output is correct
10 Correct 10 ms 2780 KB Output is correct
11 Correct 58 ms 9640 KB Output is correct
12 Correct 14 ms 3492 KB Output is correct
13 Correct 35 ms 7044 KB Output is correct
14 Correct 2 ms 1108 KB Output is correct
15 Correct 2 ms 1216 KB Output is correct
16 Correct 119 ms 16620 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Incorrect 1 ms 980 KB Tree @(3, 5) appears more than once: for edges on positions 1 and 2
19 Halted 0 ms 0 KB -