# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
564278 |
2022-05-18T19:54:41 Z |
urosk |
Pinball (JOI14_pinball) |
C++14 |
|
696 ms |
73188 KB |
// __builtin_popcount(x)
// __builtin_popcountll(x)
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 1000005
ll n,m;
ll l[maxn],r[maxn],c[maxn],val[maxn];
ll t[4*maxn];
void upd(ll v,ll tl,ll tr,ll i,ll x){
if(tl==tr){
t[v] = min(t[v],x);
return;
}
ll mid = (tl+tr)/2;
if(i<=mid) upd(2*v,tl,mid,i,x);
else upd(2*v+1,mid+1,tr,i,x);
t[v] = min(t[2*v],t[2*v+1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r){
if(l>r) return llinf;
if(tl==l&&tr==r) return t[v];
ll mid = (tl+tr)/2;
return min(get(2*v,tl,mid,l,min(mid,r)),get(2*v+1,mid+1,tr,max(mid+1,l),r));
}
ll it = 1;
map<ll,ll> mp;
ll dp[maxn][2];
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
cin >> n >> m;
set<ll> s;
s.insert(1);
s.insert(m);
for(ll i = 1;i<=n;i++){
cin >> l[i] >> r[i] >> c[i] >> val[i];
s.insert(l[i]);
s.insert(r[i]);
s.insert(c[i]);
}
for(ll x : s) mp[x] = it++;
m = mp[m];
for(ll i = 1;i<=n;i++){
l[i] = mp[l[i]];
r[i] = mp[r[i]];
c[i] = mp[c[i]];
}
vector<ll> w = {mp[1],m};
for(ll ii = 0;ii<2;ii++){
fill(t,t+4*maxn,llinf);
upd(1,1,it+1,w[ii],0);
for(ll i = 1;i<=n;i++){
dp[i][ii] = get(1,1,it+1,l[i],r[i]);
upd(1,1,it+1,c[i],dp[i][ii] + val[i]);
}
}
ll ans = llinf;
for(ll i = 1;i<=n;i++) ans = min(ans,dp[i][0] + dp[i][1] + val[i]);
if(ans==llinf) ans = -1;
cout<<ans<<endl;
return 0;
}
/*
5 6
2 4 3 5
1 2 2 8
3 6 5 2
4 6 4 7
2 4 3 10
3 5
2 4 3 10
1 3 1 20
2 5 4 30
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31572 KB |
Output is correct |
2 |
Correct |
21 ms |
31572 KB |
Output is correct |
3 |
Correct |
18 ms |
31612 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31572 KB |
Output is correct |
6 |
Correct |
18 ms |
31676 KB |
Output is correct |
7 |
Correct |
18 ms |
31676 KB |
Output is correct |
8 |
Correct |
18 ms |
31572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31572 KB |
Output is correct |
2 |
Correct |
21 ms |
31572 KB |
Output is correct |
3 |
Correct |
18 ms |
31612 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31572 KB |
Output is correct |
6 |
Correct |
18 ms |
31676 KB |
Output is correct |
7 |
Correct |
18 ms |
31676 KB |
Output is correct |
8 |
Correct |
18 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31700 KB |
Output is correct |
10 |
Correct |
22 ms |
31700 KB |
Output is correct |
11 |
Correct |
23 ms |
31628 KB |
Output is correct |
12 |
Correct |
19 ms |
31700 KB |
Output is correct |
13 |
Correct |
19 ms |
31752 KB |
Output is correct |
14 |
Correct |
18 ms |
31700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31572 KB |
Output is correct |
2 |
Correct |
21 ms |
31572 KB |
Output is correct |
3 |
Correct |
18 ms |
31612 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31572 KB |
Output is correct |
6 |
Correct |
18 ms |
31676 KB |
Output is correct |
7 |
Correct |
18 ms |
31676 KB |
Output is correct |
8 |
Correct |
18 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31700 KB |
Output is correct |
10 |
Correct |
22 ms |
31700 KB |
Output is correct |
11 |
Correct |
23 ms |
31628 KB |
Output is correct |
12 |
Correct |
19 ms |
31700 KB |
Output is correct |
13 |
Correct |
19 ms |
31752 KB |
Output is correct |
14 |
Correct |
18 ms |
31700 KB |
Output is correct |
15 |
Correct |
18 ms |
31572 KB |
Output is correct |
16 |
Correct |
18 ms |
31676 KB |
Output is correct |
17 |
Correct |
24 ms |
31792 KB |
Output is correct |
18 |
Correct |
19 ms |
31760 KB |
Output is correct |
19 |
Correct |
21 ms |
32008 KB |
Output is correct |
20 |
Correct |
19 ms |
31828 KB |
Output is correct |
21 |
Correct |
18 ms |
31844 KB |
Output is correct |
22 |
Correct |
19 ms |
32004 KB |
Output is correct |
23 |
Correct |
19 ms |
32076 KB |
Output is correct |
24 |
Correct |
21 ms |
32084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
31572 KB |
Output is correct |
2 |
Correct |
21 ms |
31572 KB |
Output is correct |
3 |
Correct |
18 ms |
31612 KB |
Output is correct |
4 |
Correct |
19 ms |
31572 KB |
Output is correct |
5 |
Correct |
18 ms |
31572 KB |
Output is correct |
6 |
Correct |
18 ms |
31676 KB |
Output is correct |
7 |
Correct |
18 ms |
31676 KB |
Output is correct |
8 |
Correct |
18 ms |
31572 KB |
Output is correct |
9 |
Correct |
18 ms |
31700 KB |
Output is correct |
10 |
Correct |
22 ms |
31700 KB |
Output is correct |
11 |
Correct |
23 ms |
31628 KB |
Output is correct |
12 |
Correct |
19 ms |
31700 KB |
Output is correct |
13 |
Correct |
19 ms |
31752 KB |
Output is correct |
14 |
Correct |
18 ms |
31700 KB |
Output is correct |
15 |
Correct |
18 ms |
31572 KB |
Output is correct |
16 |
Correct |
18 ms |
31676 KB |
Output is correct |
17 |
Correct |
24 ms |
31792 KB |
Output is correct |
18 |
Correct |
19 ms |
31760 KB |
Output is correct |
19 |
Correct |
21 ms |
32008 KB |
Output is correct |
20 |
Correct |
19 ms |
31828 KB |
Output is correct |
21 |
Correct |
18 ms |
31844 KB |
Output is correct |
22 |
Correct |
19 ms |
32004 KB |
Output is correct |
23 |
Correct |
19 ms |
32076 KB |
Output is correct |
24 |
Correct |
21 ms |
32084 KB |
Output is correct |
25 |
Correct |
43 ms |
34252 KB |
Output is correct |
26 |
Correct |
106 ms |
39996 KB |
Output is correct |
27 |
Correct |
274 ms |
48672 KB |
Output is correct |
28 |
Correct |
156 ms |
40244 KB |
Output is correct |
29 |
Correct |
189 ms |
45836 KB |
Output is correct |
30 |
Correct |
227 ms |
42144 KB |
Output is correct |
31 |
Correct |
525 ms |
58524 KB |
Output is correct |
32 |
Correct |
414 ms |
53348 KB |
Output is correct |
33 |
Correct |
80 ms |
39592 KB |
Output is correct |
34 |
Correct |
239 ms |
52340 KB |
Output is correct |
35 |
Correct |
327 ms |
72908 KB |
Output is correct |
36 |
Correct |
696 ms |
73048 KB |
Output is correct |
37 |
Correct |
525 ms |
73024 KB |
Output is correct |
38 |
Correct |
497 ms |
73188 KB |
Output is correct |