# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
340177 |
2020-12-27T08:36:23 Z |
Bill_00 |
Pinball (JOI14_pinball) |
C++14 |
|
1000 ms |
66380 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];
unordered_map<ll,bool>vis[2];
unordered_map<ll,ll>mn[2];
void update(bool type,ll up,ll id=1,ll l=1,ll r=n){
if(r<L || R<l) return;
if(L<=l && r<=R){
if(vis[type][id]){
mn[type][id]=min(mn[type][id],up);
}
else mn[type][id]=up;
vis[type][id]=1;
return;
}
ll m=l+r>>1;
update(type,up,id*2,l,m);
update(type,up,id*2+1,m+1,r);
if(!vis[type][id*2+1]){
mn[type][id]=mn[type][id*2];
vis[type][id]=1;
return;
}
if(!vis[type][id*2]){
mn[type][id]=mn[type][id*2+1];
vis[type][id]=1;
return;
}
mn[type][id]=min(mn[type][id*2],mn[type][id*2+1]);
vis[type][id]=1;
}
ll query(bool type,ll id=1,ll l=1,ll r=n){
if(r<L | R<l) return MAX;
if(L<=l && r<=R){
if(vis[type][id]) return mn[type][id];
else return MAX;
}
ll m=l+r>>1;
return min(query(type,id*2,l,m),query(type,id*2+1,m+1,r));
}
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;
update(0,0);
L=R=n;
update(1,0);
for(int i=1;i<=m;i++){
L=a[i],R=b[i];
ll cost1=query(0);
ll cost2=query(1);
if(cost1!=MAX && cost2!=MAX){
ans=min(ans,cost1+cost2+d[i]);
}
L=R=c[i];
if(cost1!=MAX){
update(0,cost1+d[i]);
}
if(cost2!=MAX){
update(1,cost2+d[i]);
}
}
if(ans==MAX) cout << -1;
else cout << ans;
}
Compilation message
pinball.cpp: In function 'void update(bool, ll, ll, ll, ll)':
pinball.cpp:27:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | ll m=l+r>>1;
| ~^~
pinball.cpp: In function 'll query(bool, ll, ll, ll)':
pinball.cpp:45:6: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
45 | if(r<L | R<l) return MAX;
| ~^~
pinball.cpp:50:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
50 | ll m=l+r>>1;
| ~^~
# |
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 |
1 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 |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 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 |
1 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 |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
3 ms |
748 KB |
Output is correct |
11 |
Correct |
4 ms |
1004 KB |
Output is correct |
12 |
Correct |
3 ms |
1004 KB |
Output is correct |
13 |
Correct |
4 ms |
1132 KB |
Output is correct |
14 |
Correct |
7 ms |
1260 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 |
1 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 |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
3 ms |
748 KB |
Output is correct |
11 |
Correct |
4 ms |
1004 KB |
Output is correct |
12 |
Correct |
3 ms |
1004 KB |
Output is correct |
13 |
Correct |
4 ms |
1132 KB |
Output is correct |
14 |
Correct |
7 ms |
1260 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
3 ms |
876 KB |
Output is correct |
17 |
Correct |
23 ms |
3564 KB |
Output is correct |
18 |
Correct |
10 ms |
620 KB |
Output is correct |
19 |
Correct |
22 ms |
4088 KB |
Output is correct |
20 |
Correct |
20 ms |
3052 KB |
Output is correct |
21 |
Correct |
5 ms |
1260 KB |
Output is correct |
22 |
Correct |
14 ms |
3192 KB |
Output is correct |
23 |
Correct |
24 ms |
4344 KB |
Output is correct |
24 |
Correct |
19 ms |
3576 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 |
1 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 |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
3 ms |
748 KB |
Output is correct |
11 |
Correct |
4 ms |
1004 KB |
Output is correct |
12 |
Correct |
3 ms |
1004 KB |
Output is correct |
13 |
Correct |
4 ms |
1132 KB |
Output is correct |
14 |
Correct |
7 ms |
1260 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
3 ms |
876 KB |
Output is correct |
17 |
Correct |
23 ms |
3564 KB |
Output is correct |
18 |
Correct |
10 ms |
620 KB |
Output is correct |
19 |
Correct |
22 ms |
4088 KB |
Output is correct |
20 |
Correct |
20 ms |
3052 KB |
Output is correct |
21 |
Correct |
5 ms |
1260 KB |
Output is correct |
22 |
Correct |
14 ms |
3192 KB |
Output is correct |
23 |
Correct |
24 ms |
4344 KB |
Output is correct |
24 |
Correct |
19 ms |
3576 KB |
Output is correct |
25 |
Correct |
215 ms |
13876 KB |
Output is correct |
26 |
Execution timed out |
1052 ms |
66380 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |