# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
340249 |
2020-12-27T10:49:17 Z |
Bill_00 |
Pinball (JOI14_pinball) |
C++14 |
|
745 ms |
179308 KB |
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define M 100005
#define MAX 1e18
typedef long long ll;
using namespace std;
ll m,n,L,R,ans=MAX;
ll a[M],b[M];
ll c[M],d[M];
struct node{
bool vis;
ll mn;
node *le,*ri;
void update(ll up,ll l,ll r){
if(r<L || R<l) return;
if(L<=l && r<=R){
if(vis){
mn=min(mn,up);
}
else mn=up;
vis=1;
return;
}
if(le==NULL) le=new node();
if(ri==NULL) ri=new node();
ll m=(l+r)>>1;
le->update(up,l,m);
ri->update(up,m+1,r);
if(!(le->vis)){
mn=ri->mn;
vis=1;
return;
}
if(!(ri->vis)){
mn=le->mn;
vis=1;
return;
}
mn=min((le->mn),(ri->mn));
vis=1;
return;
}
ll query(ll l,ll r){
if(r<L || R<l) return MAX;
if(L<=l && r<=R){
if(vis) return mn;
else return MAX;
}
if(le==NULL) return MAX;
if(ri==NULL) return MAX;
ll m=(l+r)>>1;
return min((le->query(l,m)),(ri->query(m+1,r)));
}
} *seg1=new node(),*seg2=new node();
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> m >> n;
for(int i=1;i<=m;++i){
cin >> a[i] >> b[i];
cin >> c[i] >> d[i];
}
L=R=1;
seg1->update(0,1,n);
L=R=n;
seg2->update(0,1,n);
for(int i=1;i<=m;++i){
L=a[i],R=b[i];
ll cost1=(seg1->query(1,n));
ll cost2=(seg2->query(1,n));
if(cost1!=MAX && cost2!=MAX){
ans=min(ans,cost1+cost2+d[i]);
}
L=R=c[i];
if(cost1!=MAX){
seg1->update(cost1+d[i],1,n);
}
if(cost2!=MAX){
seg2->update(cost2+d[i],1,n);
}
}
if(ans==MAX) cout << -1;
else cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
748 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
748 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
748 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
2540 KB |
Output is correct |
18 |
Correct |
3 ms |
492 KB |
Output is correct |
19 |
Correct |
4 ms |
2028 KB |
Output is correct |
20 |
Correct |
5 ms |
2156 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
2 ms |
1260 KB |
Output is correct |
23 |
Correct |
3 ms |
2156 KB |
Output is correct |
24 |
Correct |
3 ms |
1516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
620 KB |
Output is correct |
11 |
Correct |
1 ms |
748 KB |
Output is correct |
12 |
Correct |
1 ms |
620 KB |
Output is correct |
13 |
Correct |
1 ms |
620 KB |
Output is correct |
14 |
Correct |
1 ms |
748 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
2540 KB |
Output is correct |
18 |
Correct |
3 ms |
492 KB |
Output is correct |
19 |
Correct |
4 ms |
2028 KB |
Output is correct |
20 |
Correct |
5 ms |
2156 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
2 ms |
1260 KB |
Output is correct |
23 |
Correct |
3 ms |
2156 KB |
Output is correct |
24 |
Correct |
3 ms |
1516 KB |
Output is correct |
25 |
Correct |
30 ms |
9068 KB |
Output is correct |
26 |
Correct |
119 ms |
38168 KB |
Output is correct |
27 |
Correct |
413 ms |
88428 KB |
Output is correct |
28 |
Correct |
314 ms |
5996 KB |
Output is correct |
29 |
Correct |
245 ms |
76268 KB |
Output is correct |
30 |
Correct |
555 ms |
32108 KB |
Output is correct |
31 |
Correct |
745 ms |
179308 KB |
Output is correct |
32 |
Correct |
692 ms |
147564 KB |
Output is correct |
33 |
Correct |
37 ms |
15544 KB |
Output is correct |
34 |
Correct |
94 ms |
35100 KB |
Output is correct |
35 |
Correct |
243 ms |
122092 KB |
Output is correct |
36 |
Correct |
452 ms |
148716 KB |
Output is correct |
37 |
Correct |
194 ms |
73068 KB |
Output is correct |
38 |
Correct |
198 ms |
76652 KB |
Output is correct |