Submission #74242

# Submission time Handle Problem Language Result Execution time Memory
74242 2018-08-30T14:36:38 Z imeimi2000 Roller Coaster Railroad (IOI16_railroad) C++14
100 / 100
293 ms 159844 KB
#include "railroad.h"
#include <algorithm>
#include <functional>

using namespace std;
typedef long long llong;
typedef pair<int, int> pii;

vector<int> cp;
vector<int> deg;
int compress(int x) {
    return lower_bound(cp.begin(), cp.end(), x) - cp.begin();
}

vector<int> par;
int find(int x) {
    if (par[x] != -1) return par[x] = find(par[x]);
    return x;
}

int merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return 0;
    par[y] = x;
    return 1;
}

llong plan_roller_coaster(vector<int> s, vector<int> t) {
    for (int i : s) cp.push_back(i);
    for (int i : t) cp.push_back(i);
    cp.push_back(0);
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    deg.resize(cp.size(), 0);
    par.resize(cp.size(), -1);
    for (int &i : s) i = compress(i);
    for (int &i : t) i = compress(i);
    
    for (int i : s) ++deg[i];
    for (int i : t) --deg[i];
    for (int i = 0; i < s.size(); ++i) merge(s[i], t[i]);
    
    llong ret = 0;
    for (int i = 1; i < cp.size(); ++i) {
        int ch = deg[i - 1] - (i == 1);
        if (ch != 0) merge(i - 1, i);
        deg[i - 1] -= ch;
        deg[i] += ch;
        if (ch > 0) ret += (llong)ch * (cp[i] - cp[i - 1]);
    }
    
    vector<pii> es;
    for (int i = 1; i < cp.size(); ++i) es.emplace_back(cp[i] - cp[i - 1], i);
    sort(es.begin(), es.end());
    for (pii _i : es) {
        int c, i;
        tie(c, i) = _i;
        if (merge(i - 1, i)) ret += c;
    }
    return ret;
}

Compilation message

railroad.cpp: In function 'llong plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:42:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); ++i) merge(s[i], t[i]);
                     ~~^~~~~~~~~~
railroad.cpp:45:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < cp.size(); ++i) {
                     ~~^~~~~~~~~~~
railroad.cpp:54:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < cp.size(); ++i) es.emplace_back(cp[i] - cp[i - 1], i);
                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 2
2 Correct 2 ms 496 KB n = 2
3 Correct 2 ms 496 KB n = 2
4 Correct 2 ms 496 KB n = 2
5 Correct 2 ms 496 KB n = 2
6 Correct 2 ms 496 KB n = 2
7 Correct 2 ms 556 KB n = 3
8 Correct 2 ms 556 KB n = 3
9 Correct 2 ms 556 KB n = 3
10 Correct 2 ms 644 KB n = 8
11 Correct 2 ms 644 KB n = 8
12 Correct 2 ms 664 KB n = 8
13 Correct 2 ms 664 KB n = 8
14 Correct 2 ms 664 KB n = 8
15 Correct 2 ms 664 KB n = 8
16 Correct 2 ms 664 KB n = 8
17 Correct 2 ms 664 KB n = 8
18 Correct 2 ms 664 KB n = 8
19 Correct 2 ms 664 KB n = 3
20 Correct 2 ms 664 KB n = 7
21 Correct 2 ms 664 KB n = 8
22 Correct 2 ms 664 KB n = 8
23 Correct 2 ms 664 KB n = 8
24 Correct 2 ms 664 KB n = 8
25 Correct 2 ms 664 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 2
2 Correct 2 ms 496 KB n = 2
3 Correct 2 ms 496 KB n = 2
4 Correct 2 ms 496 KB n = 2
5 Correct 2 ms 496 KB n = 2
6 Correct 2 ms 496 KB n = 2
7 Correct 2 ms 556 KB n = 3
8 Correct 2 ms 556 KB n = 3
9 Correct 2 ms 556 KB n = 3
10 Correct 2 ms 644 KB n = 8
11 Correct 2 ms 644 KB n = 8
12 Correct 2 ms 664 KB n = 8
13 Correct 2 ms 664 KB n = 8
14 Correct 2 ms 664 KB n = 8
15 Correct 2 ms 664 KB n = 8
16 Correct 2 ms 664 KB n = 8
17 Correct 2 ms 664 KB n = 8
18 Correct 2 ms 664 KB n = 8
19 Correct 2 ms 664 KB n = 3
20 Correct 2 ms 664 KB n = 7
21 Correct 2 ms 664 KB n = 8
22 Correct 2 ms 664 KB n = 8
23 Correct 2 ms 664 KB n = 8
24 Correct 2 ms 664 KB n = 8
25 Correct 2 ms 664 KB n = 8
26 Correct 2 ms 664 KB n = 8
27 Correct 2 ms 664 KB n = 8
28 Correct 2 ms 664 KB n = 8
29 Correct 2 ms 664 KB n = 16
30 Correct 2 ms 664 KB n = 16
31 Correct 2 ms 664 KB n = 16
32 Correct 2 ms 664 KB n = 16
33 Correct 2 ms 664 KB n = 16
34 Correct 3 ms 664 KB n = 16
35 Correct 2 ms 664 KB n = 16
36 Correct 2 ms 664 KB n = 15
37 Correct 2 ms 664 KB n = 8
38 Correct 2 ms 764 KB n = 16
39 Correct 2 ms 764 KB n = 16
40 Correct 2 ms 764 KB n = 9
41 Correct 2 ms 764 KB n = 16
42 Correct 2 ms 764 KB n = 16
43 Correct 2 ms 764 KB n = 16
44 Correct 2 ms 764 KB n = 9
45 Correct 2 ms 764 KB n = 15
46 Correct 2 ms 764 KB n = 16
47 Correct 2 ms 764 KB n = 16
48 Correct 2 ms 764 KB n = 16
# Verdict Execution time Memory Grader output
1 Correct 289 ms 16696 KB n = 199999
2 Correct 285 ms 20704 KB n = 199991
3 Correct 285 ms 24584 KB n = 199993
4 Correct 199 ms 25264 KB n = 152076
5 Correct 131 ms 25264 KB n = 93249
6 Correct 238 ms 31100 KB n = 199910
7 Correct 266 ms 34736 KB n = 199999
8 Correct 240 ms 37104 KB n = 199997
9 Correct 248 ms 39628 KB n = 171294
10 Correct 194 ms 41128 KB n = 140872
11 Correct 250 ms 45752 KB n = 199886
12 Correct 279 ms 49408 KB n = 199996
13 Correct 268 ms 52000 KB n = 200000
14 Correct 270 ms 55348 KB n = 199998
15 Correct 264 ms 58300 KB n = 200000
16 Correct 287 ms 61832 KB n = 199998
17 Correct 257 ms 65604 KB n = 200000
18 Correct 285 ms 68972 KB n = 190000
19 Correct 230 ms 71884 KB n = 177777
20 Correct 134 ms 71884 KB n = 100000
21 Correct 293 ms 78544 KB n = 200000
22 Correct 266 ms 82416 KB n = 200000
23 Correct 270 ms 86380 KB n = 200000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n = 2
2 Correct 2 ms 496 KB n = 2
3 Correct 2 ms 496 KB n = 2
4 Correct 2 ms 496 KB n = 2
5 Correct 2 ms 496 KB n = 2
6 Correct 2 ms 496 KB n = 2
7 Correct 2 ms 556 KB n = 3
8 Correct 2 ms 556 KB n = 3
9 Correct 2 ms 556 KB n = 3
10 Correct 2 ms 644 KB n = 8
11 Correct 2 ms 644 KB n = 8
12 Correct 2 ms 664 KB n = 8
13 Correct 2 ms 664 KB n = 8
14 Correct 2 ms 664 KB n = 8
15 Correct 2 ms 664 KB n = 8
16 Correct 2 ms 664 KB n = 8
17 Correct 2 ms 664 KB n = 8
18 Correct 2 ms 664 KB n = 8
19 Correct 2 ms 664 KB n = 3
20 Correct 2 ms 664 KB n = 7
21 Correct 2 ms 664 KB n = 8
22 Correct 2 ms 664 KB n = 8
23 Correct 2 ms 664 KB n = 8
24 Correct 2 ms 664 KB n = 8
25 Correct 2 ms 664 KB n = 8
26 Correct 2 ms 664 KB n = 8
27 Correct 2 ms 664 KB n = 8
28 Correct 2 ms 664 KB n = 8
29 Correct 2 ms 664 KB n = 16
30 Correct 2 ms 664 KB n = 16
31 Correct 2 ms 664 KB n = 16
32 Correct 2 ms 664 KB n = 16
33 Correct 2 ms 664 KB n = 16
34 Correct 3 ms 664 KB n = 16
35 Correct 2 ms 664 KB n = 16
36 Correct 2 ms 664 KB n = 15
37 Correct 2 ms 664 KB n = 8
38 Correct 2 ms 764 KB n = 16
39 Correct 2 ms 764 KB n = 16
40 Correct 2 ms 764 KB n = 9
41 Correct 2 ms 764 KB n = 16
42 Correct 2 ms 764 KB n = 16
43 Correct 2 ms 764 KB n = 16
44 Correct 2 ms 764 KB n = 9
45 Correct 2 ms 764 KB n = 15
46 Correct 2 ms 764 KB n = 16
47 Correct 2 ms 764 KB n = 16
48 Correct 2 ms 764 KB n = 16
49 Correct 289 ms 16696 KB n = 199999
50 Correct 285 ms 20704 KB n = 199991
51 Correct 285 ms 24584 KB n = 199993
52 Correct 199 ms 25264 KB n = 152076
53 Correct 131 ms 25264 KB n = 93249
54 Correct 238 ms 31100 KB n = 199910
55 Correct 266 ms 34736 KB n = 199999
56 Correct 240 ms 37104 KB n = 199997
57 Correct 248 ms 39628 KB n = 171294
58 Correct 194 ms 41128 KB n = 140872
59 Correct 250 ms 45752 KB n = 199886
60 Correct 279 ms 49408 KB n = 199996
61 Correct 268 ms 52000 KB n = 200000
62 Correct 270 ms 55348 KB n = 199998
63 Correct 264 ms 58300 KB n = 200000
64 Correct 287 ms 61832 KB n = 199998
65 Correct 257 ms 65604 KB n = 200000
66 Correct 285 ms 68972 KB n = 190000
67 Correct 230 ms 71884 KB n = 177777
68 Correct 134 ms 71884 KB n = 100000
69 Correct 293 ms 78544 KB n = 200000
70 Correct 266 ms 82416 KB n = 200000
71 Correct 270 ms 86380 KB n = 200000
72 Correct 272 ms 90308 KB n = 200000
73 Correct 283 ms 94044 KB n = 200000
74 Correct 266 ms 97924 KB n = 200000
75 Correct 281 ms 101932 KB n = 200000
76 Correct 263 ms 105844 KB n = 200000
77 Correct 226 ms 106848 KB n = 200000
78 Correct 223 ms 110728 KB n = 200000
79 Correct 247 ms 116352 KB n = 184307
80 Correct 99 ms 116352 KB n = 76040
81 Correct 258 ms 120624 KB n = 199981
82 Correct 276 ms 124524 KB n = 199994
83 Correct 247 ms 126848 KB n = 199996
84 Correct 276 ms 130232 KB n = 199998
85 Correct 273 ms 133252 KB n = 200000
86 Correct 287 ms 136572 KB n = 199998
87 Correct 288 ms 140492 KB n = 200000
88 Correct 272 ms 144456 KB n = 200000
89 Correct 263 ms 148220 KB n = 200000
90 Correct 276 ms 152104 KB n = 200000
91 Correct 272 ms 155980 KB n = 200000
92 Correct 270 ms 159844 KB n = 200000