Submission #613905

# Submission time Handle Problem Language Result Execution time Memory
613905 2022-07-30T12:56:41 Z dxz05 Fountain Parks (IOI21_parks) C++17
15 / 100
316 ms 27868 KB
#include "parks.h"
#include <bits/stdc++.h>

using namespace std;
#define MP make_pair
#define all(x) (x).begin(), (x).end()

struct dsu {
    vector<int> p, sz;
    dsu(int n) {
        p.assign(n, 0);
        sz.assign(n, 1);
        iota(p.begin(), p.end(), 0);
    }

    int find(int x) {
        return (x == p[x] ? x : p[x] = find(p[x]));
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (sz[x] > sz[y]) swap(x, y);
        p[x] = y;
        sz[y] += sz[x];
        return true;
    }
};

int construct_roads(vector<int> x, vector<int> y) {
    int n = (int)x.size();
    if (n == 1) {
	    build({}, {}, {}, {});
        return 1;
    }

    map<pair<int, int>, int> id;
    for (int i = 0; i < n; i++) id[MP(x[i], y[i])] = i;

    vector<int> U, V, A, B;
    
    vector<int> perm(n);
    iota(all(perm), 0);
    sort(all(perm), [&](int i, int j){
        return MP(x[i], y[i]) < MP(x[j], y[j]);
    });

    dsu d(n);
    for (int i : perm){
        if (id.find(MP(x[i], y[i] + 2)) == id.end()) continue;
        int j = id[MP(x[i], y[i] + 2)];
        if (d.unite(i, j)){
            U.push_back(i);
            V.push_back(j);
        }
    }

    for (int i : perm) {
        if (id.find(MP(x[i] + 2, y[i])) == id.end()) continue;
        int j = id[MP(x[i] + 2, y[i])];
        if (d.unite(i, j)) {
            U.push_back(i);
            V.push_back(j);
        }
    }

    if (U.size() != n - 1) return 0;

    if (*max_element(all(x)) != 6){
        for (int it = 0; it < n - 1; it++) {
            int i = U[it], j = V[it];
            if (y[i] == y[j]) {
                A.push_back((x[i] + x[j]) / 2);
                B.push_back(y[i] + 1);
            } else {
                A.push_back((x[i] == 2 ? 1 : 5));
                B.push_back((y[i] + y[j]) / 2);
            }
        }

        build(U, V, A, B);

        return 1;
    }

    A.resize(n - 1);
    B.resize(n - 1);

    set<pair<int, int>> benches;

    for (int it = 0; it < n - 1; it++){
        int i = U[it], j = V[it];
        if (x[i] == x[j]){
            if (x[i] == 2 || x[i] == 6){
                A[it] = (x[i] == 2 ? 1 : 7);
                B[it] = (y[i] + y[j]) / 2;
                benches.insert(MP(A[it], B[it]));
            }
        } else {
            int xx = (x[i] + x[j]) / 2;
            if (xx == 3){
                A[it] = xx;
                B[it] = y[i] - 1;
            } else {
                A[it] = xx;
                B[it] = y[i] + 1;
            }
            benches.insert(MP(A[it], B[it]));
        }
    }

    for (int it = 0; it < n - 1; it++) {
        int i = U[it], j = V[it];
        if (x[i] == x[j] && x[i] == 4) {
            int yy = (y[i] + y[j]) / 2;
            B[it] = yy;
            if (!benches.count(MP(x[i] - 1, yy))){
                A[it] = x[i] - 1;
            } else {
                A[it] = x[i] + 1;
            }
        }
    }

    build(U, V, A, B);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:68:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |     if (U.size() != n - 1) return 0;
      |         ~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 113 ms 14068 KB Output is correct
10 Correct 8 ms 1832 KB Output is correct
11 Correct 62 ms 7624 KB Output is correct
12 Correct 14 ms 2560 KB Output is correct
13 Correct 31 ms 4792 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 127 ms 14060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 113 ms 14068 KB Output is correct
10 Correct 8 ms 1832 KB Output is correct
11 Correct 62 ms 7624 KB Output is correct
12 Correct 14 ms 2560 KB Output is correct
13 Correct 31 ms 4792 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 127 ms 14060 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 303 ms 27840 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 93 ms 11484 KB Output is correct
29 Correct 152 ms 16816 KB Output is correct
30 Correct 224 ms 22292 KB Output is correct
31 Correct 306 ms 27772 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 125 ms 14016 KB Output is correct
46 Correct 193 ms 20272 KB Output is correct
47 Correct 200 ms 20284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 113 ms 14068 KB Output is correct
10 Correct 8 ms 1832 KB Output is correct
11 Correct 62 ms 7624 KB Output is correct
12 Correct 14 ms 2560 KB Output is correct
13 Correct 31 ms 4792 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 127 ms 14060 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 303 ms 27840 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 93 ms 11484 KB Output is correct
29 Correct 152 ms 16816 KB Output is correct
30 Correct 224 ms 22292 KB Output is correct
31 Correct 306 ms 27772 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 125 ms 14016 KB Output is correct
46 Correct 193 ms 20272 KB Output is correct
47 Correct 200 ms 20284 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Incorrect 0 ms 212 KB Tree @(5, 3) appears more than once: for edges on positions 1 and 5
54 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 113 ms 14068 KB Output is correct
10 Correct 8 ms 1832 KB Output is correct
11 Correct 62 ms 7624 KB Output is correct
12 Correct 14 ms 2560 KB Output is correct
13 Correct 31 ms 4792 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 127 ms 14060 KB Output is correct
17 Incorrect 1 ms 212 KB Tree (a[0], b[0]) = (5, 3) is not adjacent to edge between u[0]=0 @(200000, 2) and v[0]=1 @(200000, 4)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 113 ms 14068 KB Output is correct
10 Correct 8 ms 1832 KB Output is correct
11 Correct 62 ms 7624 KB Output is correct
12 Correct 14 ms 2560 KB Output is correct
13 Correct 31 ms 4792 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 127 ms 14060 KB Output is correct
17 Incorrect 316 ms 27868 KB Tree (a[50000], b[50000]) = (5, 3) is not adjacent to edge between u[50000]=138413 @(100002, 2) and v[50000]=87394 @(100002, 4)
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 113 ms 14068 KB Output is correct
10 Correct 8 ms 1832 KB Output is correct
11 Correct 62 ms 7624 KB Output is correct
12 Correct 14 ms 2560 KB Output is correct
13 Correct 31 ms 4792 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 127 ms 14060 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 303 ms 27840 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 596 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 93 ms 11484 KB Output is correct
29 Correct 152 ms 16816 KB Output is correct
30 Correct 224 ms 22292 KB Output is correct
31 Correct 306 ms 27772 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 3 ms 596 KB Output is correct
45 Correct 125 ms 14016 KB Output is correct
46 Correct 193 ms 20272 KB Output is correct
47 Correct 200 ms 20284 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Incorrect 0 ms 212 KB Tree @(5, 3) appears more than once: for edges on positions 1 and 5
54 Halted 0 ms 0 KB -