답안 #836722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836722 2023-08-24T14:31:06 Z oscar1f Roller Coaster Railroad (IOI16_railroad) C++17
100 / 100
494 ms 69180 KB
#include<bits/stdc++.h>
#include "railroad.h"

using namespace std;
using ll=long long;

const ll MAX_TRANSFO=4*200*1000+5,INFINI=(ll)1000*1000*1000*1000*1000*1000;
ll nbTransfo,rep,nbInter;
ll seuil[MAX_TRANSFO],valNouv[MAX_TRANSFO],vraiVal[MAX_TRANSFO];
set<ll> listeInter;
ll valInter[MAX_TRANSFO];
unordered_map<ll,ll> transfo;
ll cumu[MAX_TRANSFO];
ll pere[MAX_TRANSFO];

ll find(ll pos) {
    if (pere[pos]!=pos) {
        pere[pos]=find(pere[pos]);
    }
    return pere[pos];
}

ll unir(ll deb,ll fin) {
    if (find(deb)!=find(fin)) {
        pere[find(deb)]=find(fin);
        return 1;
    }
    return 0;
}

ll plan_roller_coaster(vector<int> s,vector<int> t) {
    nbTransfo=s.size();
    for (ll i=0;i<nbTransfo;i++) {
        seuil[i]=s[i];
        listeInter.insert(seuil[i]);
        valNouv[i]=t[i];
        listeInter.insert(valNouv[i]);
    }
    seuil[nbTransfo]=INFINI;
    listeInter.insert(INFINI);
    valNouv[nbTransfo]=1;
    listeInter.insert(1);
    nbTransfo++;    
    for (ll i:listeInter) {
        vraiVal[nbInter]=i;
        transfo[i]=nbInter;
        nbInter++;
    }    
    for (ll i=0;i<nbInter;i++) {
        pere[i]=i;
    }
    for (ll i=0;i<nbTransfo;i++) {
        cumu[transfo[seuil[i]]]++;
        cumu[transfo[valNouv[i]]]--;
        unir(transfo[seuil[i]],transfo[valNouv[i]]);
    }
    vector<pair<ll,ll>> distTri;
    for (ll i=0;i<nbInter-1;i++) {
        cumu[i+1]+=cumu[i];
        rep+=(vraiVal[i+1]-vraiVal[i])*(max(cumu[i],(ll)0));
        if (cumu[i]!=0) {
            unir(i+1,i);
        }
        distTri.push_back({vraiVal[i+1]-vraiVal[i],i});
    }
    sort(distTri.begin(),distTri.end());
    for (auto i:distTri) {
        if (unir(i.second,i.second+1)==1) {
            rep+=i.first;
        }
    }
    return rep;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB n = 2
2 Correct 0 ms 340 KB n = 2
3 Correct 0 ms 340 KB n = 2
4 Correct 0 ms 340 KB n = 2
5 Correct 1 ms 340 KB n = 2
6 Correct 1 ms 340 KB n = 2
7 Correct 1 ms 340 KB n = 3
8 Correct 1 ms 464 KB n = 3
9 Correct 1 ms 340 KB n = 3
10 Correct 0 ms 340 KB n = 8
11 Correct 1 ms 340 KB n = 8
12 Correct 1 ms 340 KB n = 8
13 Correct 1 ms 340 KB n = 8
14 Correct 1 ms 320 KB n = 8
15 Correct 0 ms 340 KB n = 8
16 Correct 1 ms 340 KB n = 8
17 Correct 1 ms 340 KB n = 8
18 Correct 0 ms 340 KB n = 8
19 Correct 0 ms 340 KB n = 3
20 Correct 0 ms 340 KB n = 7
21 Correct 0 ms 340 KB n = 8
22 Correct 1 ms 340 KB n = 8
23 Correct 1 ms 340 KB n = 8
24 Correct 1 ms 464 KB n = 8
25 Correct 0 ms 340 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB n = 2
2 Correct 0 ms 340 KB n = 2
3 Correct 0 ms 340 KB n = 2
4 Correct 0 ms 340 KB n = 2
5 Correct 1 ms 340 KB n = 2
6 Correct 1 ms 340 KB n = 2
7 Correct 1 ms 340 KB n = 3
8 Correct 1 ms 464 KB n = 3
9 Correct 1 ms 340 KB n = 3
10 Correct 0 ms 340 KB n = 8
11 Correct 1 ms 340 KB n = 8
12 Correct 1 ms 340 KB n = 8
13 Correct 1 ms 340 KB n = 8
14 Correct 1 ms 320 KB n = 8
15 Correct 0 ms 340 KB n = 8
16 Correct 1 ms 340 KB n = 8
17 Correct 1 ms 340 KB n = 8
18 Correct 0 ms 340 KB n = 8
19 Correct 0 ms 340 KB n = 3
20 Correct 0 ms 340 KB n = 7
21 Correct 0 ms 340 KB n = 8
22 Correct 1 ms 340 KB n = 8
23 Correct 1 ms 340 KB n = 8
24 Correct 1 ms 464 KB n = 8
25 Correct 0 ms 340 KB n = 8
26 Correct 1 ms 340 KB n = 8
27 Correct 1 ms 340 KB n = 8
28 Correct 0 ms 340 KB n = 8
29 Correct 1 ms 340 KB n = 16
30 Correct 0 ms 340 KB n = 16
31 Correct 1 ms 340 KB n = 16
32 Correct 1 ms 340 KB n = 16
33 Correct 1 ms 340 KB n = 16
34 Correct 0 ms 340 KB n = 16
35 Correct 1 ms 340 KB n = 16
36 Correct 1 ms 340 KB n = 15
37 Correct 1 ms 340 KB n = 8
38 Correct 1 ms 340 KB n = 16
39 Correct 0 ms 340 KB n = 16
40 Correct 1 ms 340 KB n = 9
41 Correct 1 ms 340 KB n = 16
42 Correct 1 ms 340 KB n = 16
43 Correct 1 ms 340 KB n = 16
44 Correct 1 ms 340 KB n = 9
45 Correct 1 ms 340 KB n = 15
46 Correct 1 ms 340 KB n = 16
47 Correct 1 ms 340 KB n = 16
48 Correct 0 ms 340 KB n = 16
# 결과 실행 시간 메모리 Grader output
1 Correct 455 ms 68020 KB n = 199999
2 Correct 472 ms 68956 KB n = 199991
3 Correct 461 ms 69056 KB n = 199993
4 Correct 279 ms 51568 KB n = 152076
5 Correct 137 ms 32952 KB n = 93249
6 Correct 292 ms 55608 KB n = 199910
7 Correct 358 ms 67428 KB n = 199999
8 Correct 304 ms 55916 KB n = 199997
9 Correct 382 ms 56656 KB n = 171294
10 Correct 285 ms 49232 KB n = 140872
11 Correct 369 ms 56224 KB n = 199886
12 Correct 380 ms 67732 KB n = 199996
13 Correct 314 ms 57504 KB n = 200000
14 Correct 350 ms 67416 KB n = 199998
15 Correct 346 ms 66720 KB n = 200000
16 Correct 417 ms 68480 KB n = 199998
17 Correct 483 ms 69036 KB n = 200000
18 Correct 485 ms 66508 KB n = 190000
19 Correct 363 ms 63444 KB n = 177777
20 Correct 178 ms 34644 KB n = 100000
21 Correct 464 ms 69040 KB n = 200000
22 Correct 423 ms 69060 KB n = 200000
23 Correct 468 ms 69060 KB n = 200000
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB n = 2
2 Correct 0 ms 340 KB n = 2
3 Correct 0 ms 340 KB n = 2
4 Correct 0 ms 340 KB n = 2
5 Correct 1 ms 340 KB n = 2
6 Correct 1 ms 340 KB n = 2
7 Correct 1 ms 340 KB n = 3
8 Correct 1 ms 464 KB n = 3
9 Correct 1 ms 340 KB n = 3
10 Correct 0 ms 340 KB n = 8
11 Correct 1 ms 340 KB n = 8
12 Correct 1 ms 340 KB n = 8
13 Correct 1 ms 340 KB n = 8
14 Correct 1 ms 320 KB n = 8
15 Correct 0 ms 340 KB n = 8
16 Correct 1 ms 340 KB n = 8
17 Correct 1 ms 340 KB n = 8
18 Correct 0 ms 340 KB n = 8
19 Correct 0 ms 340 KB n = 3
20 Correct 0 ms 340 KB n = 7
21 Correct 0 ms 340 KB n = 8
22 Correct 1 ms 340 KB n = 8
23 Correct 1 ms 340 KB n = 8
24 Correct 1 ms 464 KB n = 8
25 Correct 0 ms 340 KB n = 8
26 Correct 1 ms 340 KB n = 8
27 Correct 1 ms 340 KB n = 8
28 Correct 0 ms 340 KB n = 8
29 Correct 1 ms 340 KB n = 16
30 Correct 0 ms 340 KB n = 16
31 Correct 1 ms 340 KB n = 16
32 Correct 1 ms 340 KB n = 16
33 Correct 1 ms 340 KB n = 16
34 Correct 0 ms 340 KB n = 16
35 Correct 1 ms 340 KB n = 16
36 Correct 1 ms 340 KB n = 15
37 Correct 1 ms 340 KB n = 8
38 Correct 1 ms 340 KB n = 16
39 Correct 0 ms 340 KB n = 16
40 Correct 1 ms 340 KB n = 9
41 Correct 1 ms 340 KB n = 16
42 Correct 1 ms 340 KB n = 16
43 Correct 1 ms 340 KB n = 16
44 Correct 1 ms 340 KB n = 9
45 Correct 1 ms 340 KB n = 15
46 Correct 1 ms 340 KB n = 16
47 Correct 1 ms 340 KB n = 16
48 Correct 0 ms 340 KB n = 16
49 Correct 455 ms 68020 KB n = 199999
50 Correct 472 ms 68956 KB n = 199991
51 Correct 461 ms 69056 KB n = 199993
52 Correct 279 ms 51568 KB n = 152076
53 Correct 137 ms 32952 KB n = 93249
54 Correct 292 ms 55608 KB n = 199910
55 Correct 358 ms 67428 KB n = 199999
56 Correct 304 ms 55916 KB n = 199997
57 Correct 382 ms 56656 KB n = 171294
58 Correct 285 ms 49232 KB n = 140872
59 Correct 369 ms 56224 KB n = 199886
60 Correct 380 ms 67732 KB n = 199996
61 Correct 314 ms 57504 KB n = 200000
62 Correct 350 ms 67416 KB n = 199998
63 Correct 346 ms 66720 KB n = 200000
64 Correct 417 ms 68480 KB n = 199998
65 Correct 483 ms 69036 KB n = 200000
66 Correct 485 ms 66508 KB n = 190000
67 Correct 363 ms 63444 KB n = 177777
68 Correct 178 ms 34644 KB n = 100000
69 Correct 464 ms 69040 KB n = 200000
70 Correct 423 ms 69060 KB n = 200000
71 Correct 468 ms 69060 KB n = 200000
72 Correct 473 ms 69180 KB n = 200000
73 Correct 438 ms 69052 KB n = 200000
74 Correct 494 ms 69064 KB n = 200000
75 Correct 467 ms 69052 KB n = 200000
76 Correct 436 ms 69048 KB n = 200000
77 Correct 188 ms 39688 KB n = 200000
78 Correct 192 ms 39656 KB n = 200000
79 Correct 423 ms 64792 KB n = 184307
80 Correct 119 ms 26116 KB n = 76040
81 Correct 356 ms 56208 KB n = 199981
82 Correct 416 ms 67732 KB n = 199994
83 Correct 348 ms 57540 KB n = 199996
84 Correct 385 ms 67436 KB n = 199998
85 Correct 368 ms 66696 KB n = 200000
86 Correct 406 ms 68400 KB n = 199998
87 Correct 446 ms 69056 KB n = 200000
88 Correct 444 ms 69048 KB n = 200000
89 Correct 423 ms 69020 KB n = 200000
90 Correct 434 ms 68996 KB n = 200000
91 Correct 436 ms 69044 KB n = 200000
92 Correct 445 ms 69064 KB n = 200000