Submission #814328

# Submission time Handle Problem Language Result Execution time Memory
814328 2023-08-08T06:52:44 Z PixelCat Fountain Parks (IOI21_parks) C++17
15 / 100
270 ms 26424 KB
#include "parks.h"

#ifdef NYAOWO
#include "grader.cpp"
#endif

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
// #define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 200'000;

struct DSU {
    int p[MAXN + 10];
    void init() {
        memset(p, -1, sizeof(p));
    }
    int find(int n) {
        if(p[n] < 0) return n;
        return p[n] = find(p[n]);
    }
    bool uni(int a, int b) {
        a = find(a); b = find(b);
        if(a == b) return false;
        p[b] = a;
        return true;
    }
} dsu;

struct PT {
    int id, x, y;
};

int construct_roads(std::vector<int> X, std::vector<int> Y) {
    if (sz(X) == 1) {
        build({}, {}, {}, {});
        return 1;
    }
    int n = sz(X);

    map<pii, int> mp;
    For(i, 0, n - 1) {
        mp[pii(X[i], Y[i])] = i;
    }
    auto find = [&](int x, int y) {
        if(mp.count(pii(x, y))) return mp[pii(x, y)];
        return -1;
    };
    vector<int> U, V, A, B;
    dsu.init();
    int cnt = 0;
    
    for(int i = 2; i < MAXN; i += 2) {
        int p1 = find(2, i);
        int p2 = find(2, i + 2);
        if(p1 >= 0 && p2 >= 0 && dsu.uni(p1, p2)) {
            U.eb(p1);
            V.eb(p2);
            A.eb(1);
            B.eb(i + 1);
            cnt++;
        }
    }
    for(int i = 2; i < MAXN; i += 2) {
        int p1 = find(4, i);
        int p2 = find(4, i + 2);
        if(p1 >= 0 && p2 >= 0 && dsu.uni(p1, p2)) {
            U.eb(p1);
            V.eb(p2);
            A.eb(5);
            B.eb(i + 1);
            cnt++;
        }
    }
    for(int i = 2; i <= MAXN; i += 2) {
        int p1 = find(2, i);
        int p2 = find(4, i);
        if(p1 >= 0 && p2 >= 0 && dsu.uni(p1, p2)) {
            U.eb(p1);
            V.eb(p2);
            A.eb(3);
            B.eb(i + 1);
            cnt++;
        }
    }
    if(cnt < n - 1) return 0;

    build(U, V, A, B);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 123 ms 13688 KB Output is correct
10 Correct 47 ms 2544 KB Output is correct
11 Correct 97 ms 7916 KB Output is correct
12 Correct 47 ms 3120 KB Output is correct
13 Correct 70 ms 5388 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 122 ms 13668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 123 ms 13688 KB Output is correct
10 Correct 47 ms 2544 KB Output is correct
11 Correct 97 ms 7916 KB Output is correct
12 Correct 47 ms 3120 KB Output is correct
13 Correct 70 ms 5388 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 122 ms 13668 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 3 ms 980 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 6 ms 1076 KB Output is correct
21 Correct 6 ms 1084 KB Output is correct
22 Correct 3 ms 980 KB Output is correct
23 Correct 246 ms 26424 KB Output is correct
24 Correct 3 ms 980 KB Output is correct
25 Correct 9 ms 1236 KB Output is correct
26 Correct 12 ms 1368 KB Output is correct
27 Correct 18 ms 1364 KB Output is correct
28 Correct 93 ms 11172 KB Output is correct
29 Correct 164 ms 16224 KB Output is correct
30 Correct 216 ms 21260 KB Output is correct
31 Correct 270 ms 26208 KB Output is correct
32 Correct 3 ms 1084 KB Output is correct
33 Correct 3 ms 1076 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 2 ms 980 KB Output is correct
36 Correct 3 ms 980 KB Output is correct
37 Correct 3 ms 980 KB Output is correct
38 Correct 2 ms 980 KB Output is correct
39 Correct 2 ms 980 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 3 ms 980 KB Output is correct
42 Correct 2 ms 980 KB Output is correct
43 Correct 10 ms 1236 KB Output is correct
44 Correct 13 ms 1408 KB Output is correct
45 Correct 115 ms 13704 KB Output is correct
46 Correct 179 ms 19348 KB Output is correct
47 Correct 192 ms 19292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 123 ms 13688 KB Output is correct
10 Correct 47 ms 2544 KB Output is correct
11 Correct 97 ms 7916 KB Output is correct
12 Correct 47 ms 3120 KB Output is correct
13 Correct 70 ms 5388 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 122 ms 13668 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 3 ms 980 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 6 ms 1076 KB Output is correct
21 Correct 6 ms 1084 KB Output is correct
22 Correct 3 ms 980 KB Output is correct
23 Correct 246 ms 26424 KB Output is correct
24 Correct 3 ms 980 KB Output is correct
25 Correct 9 ms 1236 KB Output is correct
26 Correct 12 ms 1368 KB Output is correct
27 Correct 18 ms 1364 KB Output is correct
28 Correct 93 ms 11172 KB Output is correct
29 Correct 164 ms 16224 KB Output is correct
30 Correct 216 ms 21260 KB Output is correct
31 Correct 270 ms 26208 KB Output is correct
32 Correct 3 ms 1084 KB Output is correct
33 Correct 3 ms 1076 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 2 ms 980 KB Output is correct
36 Correct 3 ms 980 KB Output is correct
37 Correct 3 ms 980 KB Output is correct
38 Correct 2 ms 980 KB Output is correct
39 Correct 2 ms 980 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 3 ms 980 KB Output is correct
42 Correct 2 ms 980 KB Output is correct
43 Correct 10 ms 1236 KB Output is correct
44 Correct 13 ms 1408 KB Output is correct
45 Correct 115 ms 13704 KB Output is correct
46 Correct 179 ms 19348 KB Output is correct
47 Correct 192 ms 19292 KB Output is correct
48 Incorrect 3 ms 980 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 123 ms 13688 KB Output is correct
10 Correct 47 ms 2544 KB Output is correct
11 Correct 97 ms 7916 KB Output is correct
12 Correct 47 ms 3120 KB Output is correct
13 Correct 70 ms 5388 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 122 ms 13668 KB Output is correct
17 Incorrect 3 ms 980 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 123 ms 13688 KB Output is correct
10 Correct 47 ms 2544 KB Output is correct
11 Correct 97 ms 7916 KB Output is correct
12 Correct 47 ms 3120 KB Output is correct
13 Correct 70 ms 5388 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 122 ms 13668 KB Output is correct
17 Incorrect 181 ms 17664 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 980 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 2 ms 980 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 980 KB Output is correct
9 Correct 123 ms 13688 KB Output is correct
10 Correct 47 ms 2544 KB Output is correct
11 Correct 97 ms 7916 KB Output is correct
12 Correct 47 ms 3120 KB Output is correct
13 Correct 70 ms 5388 KB Output is correct
14 Correct 7 ms 1108 KB Output is correct
15 Correct 8 ms 1236 KB Output is correct
16 Correct 122 ms 13668 KB Output is correct
17 Correct 2 ms 980 KB Output is correct
18 Correct 3 ms 980 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 6 ms 1076 KB Output is correct
21 Correct 6 ms 1084 KB Output is correct
22 Correct 3 ms 980 KB Output is correct
23 Correct 246 ms 26424 KB Output is correct
24 Correct 3 ms 980 KB Output is correct
25 Correct 9 ms 1236 KB Output is correct
26 Correct 12 ms 1368 KB Output is correct
27 Correct 18 ms 1364 KB Output is correct
28 Correct 93 ms 11172 KB Output is correct
29 Correct 164 ms 16224 KB Output is correct
30 Correct 216 ms 21260 KB Output is correct
31 Correct 270 ms 26208 KB Output is correct
32 Correct 3 ms 1084 KB Output is correct
33 Correct 3 ms 1076 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 2 ms 980 KB Output is correct
36 Correct 3 ms 980 KB Output is correct
37 Correct 3 ms 980 KB Output is correct
38 Correct 2 ms 980 KB Output is correct
39 Correct 2 ms 980 KB Output is correct
40 Correct 2 ms 980 KB Output is correct
41 Correct 3 ms 980 KB Output is correct
42 Correct 2 ms 980 KB Output is correct
43 Correct 10 ms 1236 KB Output is correct
44 Correct 13 ms 1408 KB Output is correct
45 Correct 115 ms 13704 KB Output is correct
46 Correct 179 ms 19348 KB Output is correct
47 Correct 192 ms 19292 KB Output is correct
48 Incorrect 3 ms 980 KB Solution announced impossible, but it is possible.
49 Halted 0 ms 0 KB -