Submission #785950

# Submission time Handle Problem Language Result Execution time Memory
785950 2023-07-17T20:09:27 Z GusterGoose27 Roller Coaster Railroad (IOI16_railroad) C++17
100 / 100
902 ms 56708 KB
#include "railroad.h"

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, int> pli;

const int MAXN = 2e5+5;
const int MAXM = 1e9+5;
const ll inf = (ll)MAXN*MAXM;
vector<pii> edges[2*MAXN];
map<int, int> conv;
int anticonv[2*MAXN];
// ll dist[2*MAXN];
bool vis[2*MAXN];

int n, m = 0;

void ins(int v) {
    if (conv.find(v) != conv.end()) return;
    conv[v] = m;
    anticonv[m++] = v;
}

ll plan_roller_coaster(vector<int> s, vector<int> t) {
    ins(1);
    ins(MAXM);
    vector<pii> events;
    events.push_back(pii(1, 0));
    events.push_back(pii(MAXM, 1));
    for (int v: s) {
        ins(v);
        events.push_back(pii(v, 1));
    }
    for (int v: t) {
        ins(v);
        events.push_back(pii(v, 0));
    }
    n = s.size();
    for (int i = 0; i < n; i++) edges[conv[s[i]]].push_back(pii(conv[t[i]], 0));
    sort(events.begin(), events.end()); // 0 start, 1 end
    int sum = 0;
    ll ans = 0;
    for (int i = 0; i < events.size()-1; i++) {
        sum += events[i].second ? -1 : 1;
        if (sum < 0) {
            edges[conv[events[i+1].first]].push_back(pii(conv[events[i].first], 0));
            ans += ((ll)events[i+1].first-events[i].first)*(-sum);
        }
        else if (sum > 0) edges[conv[events[i].first]].push_back(pii(conv[events[i+1].first], 0));
        else {
            edges[conv[events[i].first]].push_back(pii(conv[events[i+1].first], events[i+1].first-events[i].first));
            edges[conv[events[i+1].first]].push_back(pii(conv[events[i].first], events[i+1].first-events[i].first));
        }
    }
    priority_queue<pii, vector<pii>, greater<pii>> out;
    out.push(pii(0, 0));
    while (!out.empty()) {
        pii tp = out.top();
        out.pop();
        if (vis[tp.second]) continue;
        vis[tp.second] = 1;
        ans += tp.first;
        int cur = tp.second;
        for (pii p: edges[cur]) {
            if (vis[p.first]) continue;
            out.push(pii(p.second, p.first));
        }
    }
    return ans;
}

Compilation message

railroad.cpp: In function 'll plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 0; i < events.size()-1; i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB n = 2
2 Correct 5 ms 9680 KB n = 2
3 Correct 5 ms 9684 KB n = 2
4 Correct 5 ms 9676 KB n = 2
5 Correct 6 ms 9592 KB n = 2
6 Correct 5 ms 9684 KB n = 2
7 Correct 4 ms 9684 KB n = 3
8 Correct 5 ms 9684 KB n = 3
9 Correct 5 ms 9684 KB n = 3
10 Correct 4 ms 9712 KB n = 8
11 Correct 4 ms 9684 KB n = 8
12 Correct 5 ms 9684 KB n = 8
13 Correct 5 ms 9616 KB n = 8
14 Correct 5 ms 9660 KB n = 8
15 Correct 5 ms 9628 KB n = 8
16 Correct 5 ms 9684 KB n = 8
17 Correct 4 ms 9684 KB n = 8
18 Correct 4 ms 9684 KB n = 8
19 Correct 4 ms 9684 KB n = 3
20 Correct 4 ms 9684 KB n = 7
21 Correct 5 ms 9684 KB n = 8
22 Correct 4 ms 9684 KB n = 8
23 Correct 5 ms 9684 KB n = 8
24 Correct 5 ms 9684 KB n = 8
25 Correct 5 ms 9700 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB n = 2
2 Correct 5 ms 9680 KB n = 2
3 Correct 5 ms 9684 KB n = 2
4 Correct 5 ms 9676 KB n = 2
5 Correct 6 ms 9592 KB n = 2
6 Correct 5 ms 9684 KB n = 2
7 Correct 4 ms 9684 KB n = 3
8 Correct 5 ms 9684 KB n = 3
9 Correct 5 ms 9684 KB n = 3
10 Correct 4 ms 9712 KB n = 8
11 Correct 4 ms 9684 KB n = 8
12 Correct 5 ms 9684 KB n = 8
13 Correct 5 ms 9616 KB n = 8
14 Correct 5 ms 9660 KB n = 8
15 Correct 5 ms 9628 KB n = 8
16 Correct 5 ms 9684 KB n = 8
17 Correct 4 ms 9684 KB n = 8
18 Correct 4 ms 9684 KB n = 8
19 Correct 4 ms 9684 KB n = 3
20 Correct 4 ms 9684 KB n = 7
21 Correct 5 ms 9684 KB n = 8
22 Correct 4 ms 9684 KB n = 8
23 Correct 5 ms 9684 KB n = 8
24 Correct 5 ms 9684 KB n = 8
25 Correct 5 ms 9700 KB n = 8
26 Correct 6 ms 9700 KB n = 8
27 Correct 5 ms 9684 KB n = 8
28 Correct 5 ms 9704 KB n = 8
29 Correct 5 ms 9708 KB n = 16
30 Correct 5 ms 9684 KB n = 16
31 Correct 5 ms 9692 KB n = 16
32 Correct 5 ms 9684 KB n = 16
33 Correct 4 ms 9684 KB n = 16
34 Correct 5 ms 9684 KB n = 16
35 Correct 5 ms 9684 KB n = 16
36 Correct 4 ms 9684 KB n = 15
37 Correct 6 ms 9684 KB n = 8
38 Correct 5 ms 9684 KB n = 16
39 Correct 5 ms 9684 KB n = 16
40 Correct 4 ms 9700 KB n = 9
41 Correct 5 ms 9684 KB n = 16
42 Correct 5 ms 9684 KB n = 16
43 Correct 5 ms 9684 KB n = 16
44 Correct 5 ms 9704 KB n = 9
45 Correct 5 ms 9684 KB n = 15
46 Correct 4 ms 9700 KB n = 16
47 Correct 5 ms 9684 KB n = 16
48 Correct 5 ms 9684 KB n = 16
# Verdict Execution time Memory Grader output
1 Correct 669 ms 49220 KB n = 199999
2 Correct 836 ms 50728 KB n = 199991
3 Correct 668 ms 49220 KB n = 199993
4 Correct 474 ms 40648 KB n = 152076
5 Correct 250 ms 28636 KB n = 93249
6 Correct 558 ms 44016 KB n = 199910
7 Correct 633 ms 48628 KB n = 199999
8 Correct 564 ms 44276 KB n = 199997
9 Correct 566 ms 44364 KB n = 171294
10 Correct 415 ms 38420 KB n = 140872
11 Correct 614 ms 44624 KB n = 199886
12 Correct 701 ms 49140 KB n = 199996
13 Correct 614 ms 45788 KB n = 200000
14 Correct 712 ms 51856 KB n = 199998
15 Correct 687 ms 50272 KB n = 200000
16 Correct 723 ms 51172 KB n = 199998
17 Correct 601 ms 52736 KB n = 200000
18 Correct 686 ms 47192 KB n = 190000
19 Correct 483 ms 44836 KB n = 177777
20 Correct 245 ms 29688 KB n = 100000
21 Correct 679 ms 50008 KB n = 200000
22 Correct 711 ms 50812 KB n = 200000
23 Correct 737 ms 52784 KB n = 200000
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB n = 2
2 Correct 5 ms 9680 KB n = 2
3 Correct 5 ms 9684 KB n = 2
4 Correct 5 ms 9676 KB n = 2
5 Correct 6 ms 9592 KB n = 2
6 Correct 5 ms 9684 KB n = 2
7 Correct 4 ms 9684 KB n = 3
8 Correct 5 ms 9684 KB n = 3
9 Correct 5 ms 9684 KB n = 3
10 Correct 4 ms 9712 KB n = 8
11 Correct 4 ms 9684 KB n = 8
12 Correct 5 ms 9684 KB n = 8
13 Correct 5 ms 9616 KB n = 8
14 Correct 5 ms 9660 KB n = 8
15 Correct 5 ms 9628 KB n = 8
16 Correct 5 ms 9684 KB n = 8
17 Correct 4 ms 9684 KB n = 8
18 Correct 4 ms 9684 KB n = 8
19 Correct 4 ms 9684 KB n = 3
20 Correct 4 ms 9684 KB n = 7
21 Correct 5 ms 9684 KB n = 8
22 Correct 4 ms 9684 KB n = 8
23 Correct 5 ms 9684 KB n = 8
24 Correct 5 ms 9684 KB n = 8
25 Correct 5 ms 9700 KB n = 8
26 Correct 6 ms 9700 KB n = 8
27 Correct 5 ms 9684 KB n = 8
28 Correct 5 ms 9704 KB n = 8
29 Correct 5 ms 9708 KB n = 16
30 Correct 5 ms 9684 KB n = 16
31 Correct 5 ms 9692 KB n = 16
32 Correct 5 ms 9684 KB n = 16
33 Correct 4 ms 9684 KB n = 16
34 Correct 5 ms 9684 KB n = 16
35 Correct 5 ms 9684 KB n = 16
36 Correct 4 ms 9684 KB n = 15
37 Correct 6 ms 9684 KB n = 8
38 Correct 5 ms 9684 KB n = 16
39 Correct 5 ms 9684 KB n = 16
40 Correct 4 ms 9700 KB n = 9
41 Correct 5 ms 9684 KB n = 16
42 Correct 5 ms 9684 KB n = 16
43 Correct 5 ms 9684 KB n = 16
44 Correct 5 ms 9704 KB n = 9
45 Correct 5 ms 9684 KB n = 15
46 Correct 4 ms 9700 KB n = 16
47 Correct 5 ms 9684 KB n = 16
48 Correct 5 ms 9684 KB n = 16
49 Correct 669 ms 49220 KB n = 199999
50 Correct 836 ms 50728 KB n = 199991
51 Correct 668 ms 49220 KB n = 199993
52 Correct 474 ms 40648 KB n = 152076
53 Correct 250 ms 28636 KB n = 93249
54 Correct 558 ms 44016 KB n = 199910
55 Correct 633 ms 48628 KB n = 199999
56 Correct 564 ms 44276 KB n = 199997
57 Correct 566 ms 44364 KB n = 171294
58 Correct 415 ms 38420 KB n = 140872
59 Correct 614 ms 44624 KB n = 199886
60 Correct 701 ms 49140 KB n = 199996
61 Correct 614 ms 45788 KB n = 200000
62 Correct 712 ms 51856 KB n = 199998
63 Correct 687 ms 50272 KB n = 200000
64 Correct 723 ms 51172 KB n = 199998
65 Correct 601 ms 52736 KB n = 200000
66 Correct 686 ms 47192 KB n = 190000
67 Correct 483 ms 44836 KB n = 177777
68 Correct 245 ms 29688 KB n = 100000
69 Correct 679 ms 50008 KB n = 200000
70 Correct 711 ms 50812 KB n = 200000
71 Correct 737 ms 52784 KB n = 200000
72 Correct 660 ms 53048 KB n = 200000
73 Correct 759 ms 54664 KB n = 200000
74 Correct 663 ms 53004 KB n = 200000
75 Correct 577 ms 53084 KB n = 200000
76 Correct 593 ms 53100 KB n = 200000
77 Correct 384 ms 41360 KB n = 200000
78 Correct 438 ms 41548 KB n = 200000
79 Correct 639 ms 50408 KB n = 184307
80 Correct 194 ms 26660 KB n = 76040
81 Correct 584 ms 47188 KB n = 199981
82 Correct 644 ms 52300 KB n = 199994
83 Correct 580 ms 48676 KB n = 199996
84 Correct 673 ms 54716 KB n = 199998
85 Correct 692 ms 53288 KB n = 200000
86 Correct 678 ms 54496 KB n = 199998
87 Correct 657 ms 56708 KB n = 200000
88 Correct 684 ms 53096 KB n = 200000
89 Correct 570 ms 53084 KB n = 200000
90 Correct 720 ms 53868 KB n = 200000
91 Correct 806 ms 54748 KB n = 200000
92 Correct 902 ms 56696 KB n = 200000