Submission #593998

# Submission time Handle Problem Language Result Execution time Memory
593998 2022-07-11T20:51:36 Z SlavicG Fountain Parks (IOI21_parks) C++17
45 / 100
362 ms 31404 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(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 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 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 121 ms 16208 KB Output is correct
10 Correct 9 ms 2700 KB Output is correct
11 Correct 53 ms 9224 KB Output is correct
12 Correct 13 ms 3364 KB Output is correct
13 Correct 31 ms 6644 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 117 ms 15772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 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 121 ms 16208 KB Output is correct
10 Correct 9 ms 2700 KB Output is correct
11 Correct 53 ms 9224 KB Output is correct
12 Correct 13 ms 3364 KB Output is correct
13 Correct 31 ms 6644 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 117 ms 15772 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Incorrect 1 ms 980 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 1
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 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 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 121 ms 16208 KB Output is correct
10 Correct 9 ms 2700 KB Output is correct
11 Correct 53 ms 9224 KB Output is correct
12 Correct 13 ms 3364 KB Output is correct
13 Correct 31 ms 6644 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 117 ms 15772 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Incorrect 1 ms 980 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 1
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 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 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 121 ms 16208 KB Output is correct
10 Correct 9 ms 2700 KB Output is correct
11 Correct 53 ms 9224 KB Output is correct
12 Correct 13 ms 3364 KB Output is correct
13 Correct 31 ms 6644 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 117 ms 15772 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 319 ms 30440 KB Output is correct
21 Correct 324 ms 30804 KB Output is correct
22 Correct 314 ms 30244 KB Output is correct
23 Correct 258 ms 26636 KB Output is correct
24 Correct 187 ms 18968 KB Output is correct
25 Correct 237 ms 24424 KB Output is correct
26 Correct 209 ms 24508 KB Output is correct
27 Correct 274 ms 29480 KB Output is correct
28 Correct 274 ms 29676 KB Output is correct
29 Correct 293 ms 29492 KB Output is correct
30 Correct 296 ms 29508 KB Output is correct
31 Correct 1 ms 980 KB Output is correct
32 Correct 18 ms 3176 KB Output is correct
33 Correct 84 ms 9960 KB Output is correct
34 Correct 300 ms 31404 KB Output is correct
35 Correct 9 ms 2260 KB Output is correct
36 Correct 51 ms 6888 KB Output is correct
37 Correct 102 ms 12800 KB Output is correct
38 Correct 105 ms 13192 KB Output is correct
39 Correct 151 ms 17016 KB Output is correct
40 Correct 198 ms 22536 KB Output is correct
41 Correct 252 ms 26496 KB Output is correct
42 Correct 315 ms 30500 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 1236 KB Output is correct
55 Correct 3 ms 1364 KB Output is correct
56 Correct 128 ms 15376 KB Output is correct
57 Correct 193 ms 22820 KB Output is correct
58 Correct 203 ms 22744 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 272 ms 30384 KB Output is correct
63 Correct 362 ms 30648 KB Output is correct
64 Correct 275 ms 29988 KB Output is correct
65 Correct 4 ms 1620 KB Output is correct
66 Correct 7 ms 1904 KB Output is correct
67 Correct 125 ms 15248 KB Output is correct
68 Correct 202 ms 23372 KB Output is correct
69 Correct 309 ms 29792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 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 121 ms 16208 KB Output is correct
10 Correct 9 ms 2700 KB Output is correct
11 Correct 53 ms 9224 KB Output is correct
12 Correct 13 ms 3364 KB Output is correct
13 Correct 31 ms 6644 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 117 ms 15772 KB Output is correct
17 Correct 307 ms 30520 KB Output is correct
18 Correct 313 ms 30736 KB Output is correct
19 Correct 317 ms 30488 KB Output is correct
20 Correct 298 ms 28900 KB Output is correct
21 Correct 278 ms 26372 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 40 ms 5684 KB Output is correct
24 Correct 18 ms 3472 KB Output is correct
25 Correct 68 ms 9656 KB Output is correct
26 Correct 128 ms 14844 KB Output is correct
27 Correct 136 ms 15572 KB Output is correct
28 Correct 184 ms 19100 KB Output is correct
29 Correct 222 ms 23944 KB Output is correct
30 Correct 261 ms 26912 KB Output is correct
31 Correct 323 ms 30496 KB Output is correct
32 Correct 323 ms 30444 KB Output is correct
33 Correct 345 ms 30756 KB Output is correct
34 Correct 4 ms 1620 KB Output is correct
35 Correct 7 ms 2176 KB Output is correct
36 Correct 125 ms 15156 KB Output is correct
37 Correct 209 ms 23248 KB Output is correct
38 Correct 335 ms 29608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 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 121 ms 16208 KB Output is correct
10 Correct 9 ms 2700 KB Output is correct
11 Correct 53 ms 9224 KB Output is correct
12 Correct 13 ms 3364 KB Output is correct
13 Correct 31 ms 6644 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 117 ms 15772 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Incorrect 1 ms 980 KB Tree @(3, 5) appears more than once: for edges on positions 0 and 1
19 Halted 0 ms 0 KB -