#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;
int F[LIM], akt;
int fnd(int x) {
if(F[x]==x) return x;
return F[x]=fnd(F[x]);
}
void uni(int a, int b) {
if(fnd(a)==fnd(b)) return;
F[fnd(b)]=fnd(a);
}
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()) 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));
int lst=P[0].st;
ll sum=0;
for(auto i : P) {
if(i.st!=lst) {
if(sum<0) return 1;
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]]);
rep(i, akt) if(fnd(i)!=fnd(0)) return 1;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 2 |
2 |
Correct |
1 ms |
348 KB |
n = 2 |
3 |
Correct |
0 ms |
348 KB |
n = 2 |
4 |
Correct |
1 ms |
348 KB |
n = 2 |
5 |
Correct |
0 ms |
348 KB |
n = 2 |
6 |
Incorrect |
1 ms |
348 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 2 |
2 |
Correct |
1 ms |
348 KB |
n = 2 |
3 |
Correct |
0 ms |
348 KB |
n = 2 |
4 |
Correct |
1 ms |
348 KB |
n = 2 |
5 |
Correct |
0 ms |
348 KB |
n = 2 |
6 |
Incorrect |
1 ms |
348 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
506 ms |
30516 KB |
n = 199999 |
2 |
Correct |
207 ms |
30588 KB |
n = 199991 |
3 |
Correct |
207 ms |
30108 KB |
n = 199993 |
4 |
Correct |
349 ms |
23596 KB |
n = 152076 |
5 |
Correct |
212 ms |
15416 KB |
n = 93249 |
6 |
Correct |
449 ms |
27280 KB |
n = 199910 |
7 |
Correct |
444 ms |
30780 KB |
n = 199999 |
8 |
Correct |
410 ms |
27188 KB |
n = 199997 |
9 |
Correct |
397 ms |
26352 KB |
n = 171294 |
10 |
Correct |
338 ms |
23048 KB |
n = 140872 |
11 |
Correct |
400 ms |
28848 KB |
n = 199886 |
12 |
Correct |
417 ms |
32524 KB |
n = 199996 |
13 |
Correct |
407 ms |
29712 KB |
n = 200000 |
14 |
Correct |
183 ms |
32172 KB |
n = 199998 |
15 |
Correct |
197 ms |
31848 KB |
n = 200000 |
16 |
Correct |
208 ms |
32944 KB |
n = 199998 |
17 |
Correct |
192 ms |
33464 KB |
n = 200000 |
18 |
Correct |
184 ms |
32004 KB |
n = 190000 |
19 |
Correct |
404 ms |
31268 KB |
n = 177777 |
20 |
Correct |
167 ms |
16880 KB |
n = 100000 |
21 |
Correct |
431 ms |
33432 KB |
n = 200000 |
22 |
Correct |
360 ms |
33460 KB |
n = 200000 |
23 |
Correct |
449 ms |
33712 KB |
n = 200000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 2 |
2 |
Correct |
1 ms |
348 KB |
n = 2 |
3 |
Correct |
0 ms |
348 KB |
n = 2 |
4 |
Correct |
1 ms |
348 KB |
n = 2 |
5 |
Correct |
0 ms |
348 KB |
n = 2 |
6 |
Incorrect |
1 ms |
348 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |