#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=3e5+5,mod=1e9+7,Inf=1e17;
int t,tree[4*N][2],a[N],b[N],c[N],d[N],n,R;
vector<int>p;
string s;
map<int,int> ind;
void build(int u,int l,int r,int type){
tree[u][type]=Inf;
if(l==r) return;
int mid=(l+r)/2;
build(2*u,l,mid,type);
build(2*u+1,mid+1,r,type);
}
void update(int u,int ind,int l,int r,int type,int val){
if(l>ind || r<ind) return;
if(l==r) {
tree[u][type]=min(tree[u][type],val);
return;
}
int mid=(l+r)/2;
update(2*u,ind,l,mid,type,val);
update(2*u+1,ind,mid+1,r,type,val);
tree[u][type]=min(tree[2*u][type],tree[2*u+1][type]);
}
int getans(int u,int start,int end,int l,int r,int type){
if(l>end || r<start) return Inf;
if(start<=l && r<=end){
return tree[u][type];
}
int mid=(l+r)/2;
return min(getans(2*u,start,end,l,mid,type),getans(2*u+1,start,end,mid+1,r,type));
}
main(){
// t=1;
cin>>n>>R;
p.push_back(1);
p.push_back(R);
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i]>>c[i]>>d[i];
p.push_back(a[i]);
p.push_back(b[i]);
p.push_back(c[i]);
}
sort(p.begin(),p.end());
int cur = 0;
for(int i=0;i<p.size();i++){
if(!i || p[i]!=p[i-1]) cur++;
ind[p[i]]=cur;
}
build(1,1,cur,0);
update(1,1,1,cur,0,0);
build(1,1,cur,1);
update(1,cur,1,cur,1,0);
int ans = Inf;
for(int i=1;i<=n;i++){
int cost1=getans(1,ind[a[i]],ind[b[i]],1,cur,0);
int costR=getans(1,ind[a[i]],ind[b[i]],1,cur,1);
// cout<<cost1<<" "<<costR<<endl;
ans=min(ans,cost1+costR+d[i]);
update(1,ind[c[i]],1,cur,0,cost1+d[i]);
update(1,ind[c[i]],1,cur,1,costR+d[i]);
}
if(ans==Inf) cout<<-1;
else cout<<ans;
}
Compilation message
pinball.cpp:37:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
37 | main(){
| ^
pinball.cpp: In function 'int main()':
pinball.cpp:50:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<p.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
588 KB |
Output is correct |
20 |
Correct |
4 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
5 ms |
716 KB |
Output is correct |
23 |
Correct |
4 ms |
588 KB |
Output is correct |
24 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
5 ms |
588 KB |
Output is correct |
20 |
Correct |
4 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
5 ms |
716 KB |
Output is correct |
23 |
Correct |
4 ms |
588 KB |
Output is correct |
24 |
Correct |
4 ms |
588 KB |
Output is correct |
25 |
Correct |
44 ms |
2888 KB |
Output is correct |
26 |
Correct |
136 ms |
7192 KB |
Output is correct |
27 |
Correct |
478 ms |
14768 KB |
Output is correct |
28 |
Correct |
322 ms |
7276 KB |
Output is correct |
29 |
Correct |
309 ms |
12788 KB |
Output is correct |
30 |
Correct |
439 ms |
7976 KB |
Output is correct |
31 |
Correct |
754 ms |
24592 KB |
Output is correct |
32 |
Correct |
753 ms |
17452 KB |
Output is correct |
33 |
Correct |
90 ms |
7100 KB |
Output is correct |
34 |
Correct |
345 ms |
20664 KB |
Output is correct |
35 |
Correct |
500 ms |
40964 KB |
Output is correct |
36 |
Correct |
889 ms |
44864 KB |
Output is correct |
37 |
Correct |
699 ms |
44872 KB |
Output is correct |
38 |
Correct |
705 ms |
44848 KB |
Output is correct |