#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=2e5+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++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 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 |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
316 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 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 |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
316 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 |
460 KB |
Output is correct |
19 |
Correct |
5 ms |
716 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 |
716 KB |
Output is correct |
24 |
Correct |
5 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
292 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 |
308 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
316 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 |
460 KB |
Output is correct |
19 |
Correct |
5 ms |
716 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 |
716 KB |
Output is correct |
24 |
Correct |
5 ms |
716 KB |
Output is correct |
25 |
Correct |
44 ms |
3172 KB |
Output is correct |
26 |
Correct |
147 ms |
8120 KB |
Output is correct |
27 |
Correct |
441 ms |
17044 KB |
Output is correct |
28 |
Correct |
327 ms |
10716 KB |
Output is correct |
29 |
Correct |
325 ms |
14812 KB |
Output is correct |
30 |
Correct |
451 ms |
11836 KB |
Output is correct |
31 |
Correct |
738 ms |
28456 KB |
Output is correct |
32 |
Correct |
670 ms |
21456 KB |
Output is correct |
33 |
Correct |
91 ms |
7740 KB |
Output is correct |
34 |
Correct |
365 ms |
22584 KB |
Output is correct |
35 |
Runtime error |
296 ms |
71080 KB |
Execution killed with signal 11 |
36 |
Halted |
0 ms |
0 KB |
- |