Submission #989518

# Submission time Handle Problem Language Result Execution time Memory
989518 2024-05-28T08:50:37 Z AdamGS Roller Coaster Railroad (IOI16_railroad) C++17
100 / 100
505 ms 49024 KB
#include "railroad.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=4e5+7, INF=1e9+7;
vector<int>skal;
map<int,int>mp;
ll jaki[LIM];
int F[LIM], akt;
int fnd(int x) {
  if(F[x]==x) return x;
  return F[x]=fnd(F[x]);
}
bool uni(int a, int b) {
  if(fnd(a)==fnd(b)) return false;
  F[fnd(b)]=fnd(a);
  return true;
}
ll plan_roller_coaster(vector<int>s, vector<int>t) {
  s.pb(INF);
  t.pb(0);
  int n=s.size();
  for(auto i : s) skal.pb(i);
  for(auto i : t) skal.pb(i);
  sort(all(skal));
  for(auto i : skal) if(mp.find(i)==mp.end()) {
    jaki[akt]=i;
    mp[i]=akt++;
  }
  rep(i, akt) F[i]=i;
  vector<pair<int,int>>P;
  rep(i, n) {
    P.pb({s[i], -1});
    P.pb({t[i], 1});
  }
  sort(all(P));
  ll lst=P[0].st, sum=0, ans=0;
  for(auto i : P) {
    if(i.st!=lst) {
      if(sum<0) ans-=sum*(i.st-lst);
      if(sum!=0) uni(mp[i.st], mp[lst]);
    }
    sum+=i.nd;
    lst=i.st;
  }
  rep(i, n) uni(mp[s[i]], mp[t[i]]);
  vector<pair<ll,pair<int,int>>>kraw;
  rep(i, akt-1) kraw.pb({jaki[i+1]-jaki[i], {i, i+1}});
  sort(all(kraw));
  for(auto i : kraw) if(uni(i.nd.st, i.nd.nd)) ans+=i.st;
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 2
2 Correct 0 ms 348 KB n = 2
3 Correct 0 ms 348 KB n = 2
4 Correct 0 ms 348 KB n = 2
5 Correct 0 ms 348 KB n = 2
6 Correct 0 ms 348 KB n = 2
7 Correct 0 ms 344 KB n = 3
8 Correct 0 ms 348 KB n = 3
9 Correct 0 ms 348 KB n = 3
10 Correct 0 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 0 ms 348 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 0 ms 348 KB n = 8
16 Correct 0 ms 348 KB n = 8
17 Correct 0 ms 348 KB n = 8
18 Correct 0 ms 348 KB n = 8
19 Correct 0 ms 348 KB n = 3
20 Correct 0 ms 348 KB n = 7
21 Correct 0 ms 348 KB n = 8
22 Correct 0 ms 348 KB n = 8
23 Correct 0 ms 348 KB n = 8
24 Correct 0 ms 348 KB n = 8
25 Correct 0 ms 348 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 2
2 Correct 0 ms 348 KB n = 2
3 Correct 0 ms 348 KB n = 2
4 Correct 0 ms 348 KB n = 2
5 Correct 0 ms 348 KB n = 2
6 Correct 0 ms 348 KB n = 2
7 Correct 0 ms 344 KB n = 3
8 Correct 0 ms 348 KB n = 3
9 Correct 0 ms 348 KB n = 3
10 Correct 0 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 0 ms 348 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 0 ms 348 KB n = 8
16 Correct 0 ms 348 KB n = 8
17 Correct 0 ms 348 KB n = 8
18 Correct 0 ms 348 KB n = 8
19 Correct 0 ms 348 KB n = 3
20 Correct 0 ms 348 KB n = 7
21 Correct 0 ms 348 KB n = 8
22 Correct 0 ms 348 KB n = 8
23 Correct 0 ms 348 KB n = 8
24 Correct 0 ms 348 KB n = 8
25 Correct 0 ms 348 KB n = 8
26 Correct 1 ms 348 KB n = 8
27 Correct 0 ms 348 KB n = 8
28 Correct 0 ms 348 KB n = 8
29 Correct 0 ms 348 KB n = 16
30 Correct 0 ms 348 KB n = 16
31 Correct 0 ms 348 KB n = 16
32 Correct 0 ms 344 KB n = 16
33 Correct 0 ms 448 KB n = 16
34 Correct 0 ms 348 KB n = 16
35 Correct 0 ms 440 KB n = 16
36 Correct 0 ms 348 KB n = 15
37 Correct 0 ms 440 KB n = 8
38 Correct 0 ms 348 KB n = 16
39 Correct 0 ms 348 KB n = 16
40 Correct 0 ms 348 KB n = 9
41 Correct 0 ms 348 KB n = 16
42 Correct 0 ms 348 KB n = 16
43 Correct 0 ms 348 KB n = 16
44 Correct 0 ms 348 KB n = 9
45 Correct 0 ms 444 KB n = 15
46 Correct 0 ms 344 KB n = 16
47 Correct 0 ms 348 KB n = 16
48 Correct 0 ms 348 KB n = 16
# Verdict Execution time Memory Grader output
1 Correct 505 ms 45760 KB n = 199999
2 Correct 447 ms 47916 KB n = 199991
3 Correct 468 ms 47292 KB n = 199993
4 Correct 336 ms 36624 KB n = 152076
5 Correct 180 ms 23004 KB n = 93249
6 Correct 364 ms 40752 KB n = 199910
7 Correct 415 ms 45416 KB n = 199999
8 Correct 363 ms 41008 KB n = 199997
9 Correct 368 ms 40456 KB n = 171294
10 Correct 297 ms 34948 KB n = 140872
11 Correct 333 ms 38960 KB n = 199886
12 Correct 377 ms 42784 KB n = 199996
13 Correct 350 ms 39724 KB n = 200000
14 Correct 384 ms 42536 KB n = 199998
15 Correct 364 ms 42032 KB n = 200000
16 Correct 399 ms 43344 KB n = 199998
17 Correct 434 ms 46880 KB n = 200000
18 Correct 426 ms 42424 KB n = 190000
19 Correct 371 ms 42260 KB n = 177777
20 Correct 183 ms 22328 KB n = 100000
21 Correct 402 ms 44072 KB n = 200000
22 Correct 399 ms 43812 KB n = 200000
23 Correct 391 ms 43812 KB n = 200000
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 2
2 Correct 0 ms 348 KB n = 2
3 Correct 0 ms 348 KB n = 2
4 Correct 0 ms 348 KB n = 2
5 Correct 0 ms 348 KB n = 2
6 Correct 0 ms 348 KB n = 2
7 Correct 0 ms 344 KB n = 3
8 Correct 0 ms 348 KB n = 3
9 Correct 0 ms 348 KB n = 3
10 Correct 0 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 0 ms 348 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 0 ms 348 KB n = 8
16 Correct 0 ms 348 KB n = 8
17 Correct 0 ms 348 KB n = 8
18 Correct 0 ms 348 KB n = 8
19 Correct 0 ms 348 KB n = 3
20 Correct 0 ms 348 KB n = 7
21 Correct 0 ms 348 KB n = 8
22 Correct 0 ms 348 KB n = 8
23 Correct 0 ms 348 KB n = 8
24 Correct 0 ms 348 KB n = 8
25 Correct 0 ms 348 KB n = 8
26 Correct 1 ms 348 KB n = 8
27 Correct 0 ms 348 KB n = 8
28 Correct 0 ms 348 KB n = 8
29 Correct 0 ms 348 KB n = 16
30 Correct 0 ms 348 KB n = 16
31 Correct 0 ms 348 KB n = 16
32 Correct 0 ms 344 KB n = 16
33 Correct 0 ms 448 KB n = 16
34 Correct 0 ms 348 KB n = 16
35 Correct 0 ms 440 KB n = 16
36 Correct 0 ms 348 KB n = 15
37 Correct 0 ms 440 KB n = 8
38 Correct 0 ms 348 KB n = 16
39 Correct 0 ms 348 KB n = 16
40 Correct 0 ms 348 KB n = 9
41 Correct 0 ms 348 KB n = 16
42 Correct 0 ms 348 KB n = 16
43 Correct 0 ms 348 KB n = 16
44 Correct 0 ms 348 KB n = 9
45 Correct 0 ms 444 KB n = 15
46 Correct 0 ms 344 KB n = 16
47 Correct 0 ms 348 KB n = 16
48 Correct 0 ms 348 KB n = 16
49 Correct 505 ms 45760 KB n = 199999
50 Correct 447 ms 47916 KB n = 199991
51 Correct 468 ms 47292 KB n = 199993
52 Correct 336 ms 36624 KB n = 152076
53 Correct 180 ms 23004 KB n = 93249
54 Correct 364 ms 40752 KB n = 199910
55 Correct 415 ms 45416 KB n = 199999
56 Correct 363 ms 41008 KB n = 199997
57 Correct 368 ms 40456 KB n = 171294
58 Correct 297 ms 34948 KB n = 140872
59 Correct 333 ms 38960 KB n = 199886
60 Correct 377 ms 42784 KB n = 199996
61 Correct 350 ms 39724 KB n = 200000
62 Correct 384 ms 42536 KB n = 199998
63 Correct 364 ms 42032 KB n = 200000
64 Correct 399 ms 43344 KB n = 199998
65 Correct 434 ms 46880 KB n = 200000
66 Correct 426 ms 42424 KB n = 190000
67 Correct 371 ms 42260 KB n = 177777
68 Correct 183 ms 22328 KB n = 100000
69 Correct 402 ms 44072 KB n = 200000
70 Correct 399 ms 43812 KB n = 200000
71 Correct 391 ms 43812 KB n = 200000
72 Correct 442 ms 46372 KB n = 200000
73 Correct 433 ms 46804 KB n = 200000
74 Correct 440 ms 49024 KB n = 200000
75 Correct 439 ms 46884 KB n = 200000
76 Correct 416 ms 46116 KB n = 200000
77 Correct 277 ms 31912 KB n = 200000
78 Correct 239 ms 29864 KB n = 200000
79 Correct 399 ms 43300 KB n = 184307
80 Correct 162 ms 19836 KB n = 76040
81 Correct 344 ms 38936 KB n = 199981
82 Correct 414 ms 42800 KB n = 199994
83 Correct 346 ms 39716 KB n = 199996
84 Correct 400 ms 42484 KB n = 199998
85 Correct 386 ms 42024 KB n = 200000
86 Correct 403 ms 43292 KB n = 199998
87 Correct 437 ms 46884 KB n = 200000
88 Correct 437 ms 44328 KB n = 200000
89 Correct 420 ms 46376 KB n = 200000
90 Correct 413 ms 43984 KB n = 200000
91 Correct 393 ms 43812 KB n = 200000
92 Correct 416 ms 43824 KB n = 200000