#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) 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 |
0 ms |
348 KB |
n = 2 |
3 |
Correct |
1 ms |
348 KB |
n = 2 |
4 |
Correct |
0 ms |
348 KB |
n = 2 |
5 |
Correct |
1 ms |
348 KB |
n = 2 |
6 |
Incorrect |
0 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 |
0 ms |
348 KB |
n = 2 |
3 |
Correct |
1 ms |
348 KB |
n = 2 |
4 |
Correct |
0 ms |
348 KB |
n = 2 |
5 |
Correct |
1 ms |
348 KB |
n = 2 |
6 |
Incorrect |
0 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 |
264 ms |
33968 KB |
n = 199999 |
2 |
Correct |
203 ms |
34740 KB |
n = 199991 |
3 |
Correct |
184 ms |
34992 KB |
n = 199993 |
4 |
Correct |
190 ms |
29796 KB |
n = 152076 |
5 |
Correct |
112 ms |
17712 KB |
n = 93249 |
6 |
Correct |
225 ms |
32428 KB |
n = 199910 |
7 |
Correct |
248 ms |
37032 KB |
n = 199999 |
8 |
Correct |
226 ms |
32728 KB |
n = 199997 |
9 |
Correct |
215 ms |
32160 KB |
n = 171294 |
10 |
Correct |
173 ms |
28416 KB |
n = 140872 |
11 |
Correct |
222 ms |
29360 KB |
n = 199886 |
12 |
Correct |
253 ms |
34732 KB |
n = 199996 |
13 |
Correct |
230 ms |
30556 KB |
n = 200000 |
14 |
Correct |
186 ms |
32676 KB |
n = 199998 |
15 |
Correct |
182 ms |
31924 KB |
n = 200000 |
16 |
Correct |
186 ms |
33272 KB |
n = 199998 |
17 |
Correct |
183 ms |
34732 KB |
n = 200000 |
18 |
Correct |
175 ms |
32296 KB |
n = 190000 |
19 |
Correct |
225 ms |
34388 KB |
n = 177777 |
20 |
Incorrect |
117 ms |
17088 KB |
answer is not correct: 1 instead of 0 |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 2 |
2 |
Correct |
0 ms |
348 KB |
n = 2 |
3 |
Correct |
1 ms |
348 KB |
n = 2 |
4 |
Correct |
0 ms |
348 KB |
n = 2 |
5 |
Correct |
1 ms |
348 KB |
n = 2 |
6 |
Incorrect |
0 ms |
348 KB |
answer is not correct: 1 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |