#include "railroad.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define mp(x,y) make_pair(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 200000000000000000
#define inff 200000000
#define MOD 1000000007
#define N 200005
#define MAX 10000006
#define LOG 30
#define KOK 200
using namespace std;
ll full;
bool vis[16][pw(16)];
int n;
int pos[N];
ll dp[16][pw(16)];
vector<ii> v[16];
vector<int> rails,s,t;
ii S[N*4];
ii merge(ii x,ii y) {
if(y.st<x.st) return y;
return x;
}
void up(int node,int bas,int son,int x) {
if(bas>x || son<x) return ;
if(bas==x && son==x) {
S[node]={inff,-1};
return ;
}
up(node<<1,bas,orta,x);
up(node<<1|1,orta+1,son,x);
S[node]=merge(S[node*2],S[node*2+1]);
}
ii get(int node,int bas,int son,int now) {
if(bas>son || s[son]<now) return mp(inff,-1);
if(s[bas]>=now) return S[node];
return merge(get(node<<1,bas,orta,now),get(node<<1|1,orta+1,son,now));
}
void build(int node,int bas,int son) {
if(bas==son) {
S[node]={t[pos[bas]],bas};
return ;
}
build(node<<1,bas,orta);
build(node<<1|1,orta+1,son);
S[node]=merge(S[node<<1],S[node<<1|1]);
}
ll S3(vector<int>&ss, vector<int>& tt) {
n=sz(ss);
for(int i=0;i<n;i++) s.pb(ss[i]),t.pb(tt[i]);
for(int i=0;i<n;i++) rails.pb(i);
sort(all(rails),[](int x,int y) {
if(s[x]<s[y]) return true;
if(s[x]>s[y]) return false;
if(t[x]<t[y]) return true;
return false;
});
for(int i=0;i<n;i++) pos[i]=rails[i];
build(1,0,n-1);
int cur_pos=1;
int total=0;
while(total<n) {
ii best=get(1,0,n-1,cur_pos);
if(best.nd==-1) return 0;
up(1,0,n-1,best.nd);
cur_pos=best.st;
total++;
}
return 1;
}
ll solve(int now,int mask) {
if(vis[now][mask]) return dp[now][mask];
if(mask==full) return 0;
vis[now][mask]=1;
ll& r=dp[now][mask];
r=inf;
for(int i=0;i<sz(v[now]);i++) {
if(mask&pw(v[now][i].nd)) continue ;
umin(r,solve(v[now][i].nd,mask|pw(v[now][i].nd))+v[now][i].st);
}
return r;
}
ll S12(vector<int>&s, vector<int>& t) {
for(int i=0;i<sz(s);i++) {
for(int j=0;j<sz(s);j++) {
if(i==j) continue ;
v[i].pb({max(0,t[i]-s[j]),j});
}
}
full=pw(sz(s))-1;
ll ans=inf;
for(int i=0;i<sz(s);i++) {
umin(ans,solve(i,pw(i)));
}
return ans;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
if(sz(s)<=16) return S12(s,t);
else return S3(s,t);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 2 |
2 |
Correct |
2 ms |
356 KB |
n = 2 |
3 |
Correct |
3 ms |
408 KB |
n = 2 |
4 |
Correct |
2 ms |
408 KB |
n = 2 |
5 |
Correct |
3 ms |
592 KB |
n = 2 |
6 |
Correct |
2 ms |
592 KB |
n = 2 |
7 |
Correct |
2 ms |
592 KB |
n = 3 |
8 |
Correct |
3 ms |
616 KB |
n = 3 |
9 |
Correct |
3 ms |
744 KB |
n = 3 |
10 |
Correct |
2 ms |
744 KB |
n = 8 |
11 |
Correct |
3 ms |
744 KB |
n = 8 |
12 |
Correct |
2 ms |
744 KB |
n = 8 |
13 |
Correct |
2 ms |
744 KB |
n = 8 |
14 |
Correct |
2 ms |
744 KB |
n = 8 |
15 |
Correct |
2 ms |
744 KB |
n = 8 |
16 |
Correct |
3 ms |
744 KB |
n = 8 |
17 |
Correct |
3 ms |
744 KB |
n = 8 |
18 |
Correct |
2 ms |
744 KB |
n = 8 |
19 |
Correct |
2 ms |
744 KB |
n = 3 |
20 |
Correct |
2 ms |
744 KB |
n = 7 |
21 |
Correct |
3 ms |
744 KB |
n = 8 |
22 |
Correct |
3 ms |
744 KB |
n = 8 |
23 |
Correct |
2 ms |
744 KB |
n = 8 |
24 |
Correct |
2 ms |
744 KB |
n = 8 |
25 |
Correct |
2 ms |
744 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 2 |
2 |
Correct |
2 ms |
356 KB |
n = 2 |
3 |
Correct |
3 ms |
408 KB |
n = 2 |
4 |
Correct |
2 ms |
408 KB |
n = 2 |
5 |
Correct |
3 ms |
592 KB |
n = 2 |
6 |
Correct |
2 ms |
592 KB |
n = 2 |
7 |
Correct |
2 ms |
592 KB |
n = 3 |
8 |
Correct |
3 ms |
616 KB |
n = 3 |
9 |
Correct |
3 ms |
744 KB |
n = 3 |
10 |
Correct |
2 ms |
744 KB |
n = 8 |
11 |
Correct |
3 ms |
744 KB |
n = 8 |
12 |
Correct |
2 ms |
744 KB |
n = 8 |
13 |
Correct |
2 ms |
744 KB |
n = 8 |
14 |
Correct |
2 ms |
744 KB |
n = 8 |
15 |
Correct |
2 ms |
744 KB |
n = 8 |
16 |
Correct |
3 ms |
744 KB |
n = 8 |
17 |
Correct |
3 ms |
744 KB |
n = 8 |
18 |
Correct |
2 ms |
744 KB |
n = 8 |
19 |
Correct |
2 ms |
744 KB |
n = 3 |
20 |
Correct |
2 ms |
744 KB |
n = 7 |
21 |
Correct |
3 ms |
744 KB |
n = 8 |
22 |
Correct |
3 ms |
744 KB |
n = 8 |
23 |
Correct |
2 ms |
744 KB |
n = 8 |
24 |
Correct |
2 ms |
744 KB |
n = 8 |
25 |
Correct |
2 ms |
744 KB |
n = 8 |
26 |
Correct |
2 ms |
744 KB |
n = 8 |
27 |
Correct |
2 ms |
744 KB |
n = 8 |
28 |
Correct |
3 ms |
744 KB |
n = 8 |
29 |
Correct |
95 ms |
8464 KB |
n = 16 |
30 |
Correct |
103 ms |
8464 KB |
n = 16 |
31 |
Correct |
100 ms |
8576 KB |
n = 16 |
32 |
Correct |
85 ms |
8576 KB |
n = 16 |
33 |
Correct |
101 ms |
8576 KB |
n = 16 |
34 |
Correct |
107 ms |
8576 KB |
n = 16 |
35 |
Correct |
109 ms |
8576 KB |
n = 16 |
36 |
Correct |
45 ms |
8576 KB |
n = 15 |
37 |
Correct |
3 ms |
8576 KB |
n = 8 |
38 |
Correct |
89 ms |
8576 KB |
n = 16 |
39 |
Correct |
116 ms |
8576 KB |
n = 16 |
40 |
Correct |
3 ms |
8576 KB |
n = 9 |
41 |
Correct |
116 ms |
8576 KB |
n = 16 |
42 |
Correct |
123 ms |
8576 KB |
n = 16 |
43 |
Correct |
111 ms |
8624 KB |
n = 16 |
44 |
Correct |
3 ms |
8624 KB |
n = 9 |
45 |
Correct |
33 ms |
8624 KB |
n = 15 |
46 |
Correct |
116 ms |
8624 KB |
n = 16 |
47 |
Correct |
111 ms |
8624 KB |
n = 16 |
48 |
Correct |
81 ms |
8624 KB |
n = 16 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
11152 KB |
n = 199999 |
2 |
Incorrect |
156 ms |
11152 KB |
answer is not correct: 0 instead of 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 2 |
2 |
Correct |
2 ms |
356 KB |
n = 2 |
3 |
Correct |
3 ms |
408 KB |
n = 2 |
4 |
Correct |
2 ms |
408 KB |
n = 2 |
5 |
Correct |
3 ms |
592 KB |
n = 2 |
6 |
Correct |
2 ms |
592 KB |
n = 2 |
7 |
Correct |
2 ms |
592 KB |
n = 3 |
8 |
Correct |
3 ms |
616 KB |
n = 3 |
9 |
Correct |
3 ms |
744 KB |
n = 3 |
10 |
Correct |
2 ms |
744 KB |
n = 8 |
11 |
Correct |
3 ms |
744 KB |
n = 8 |
12 |
Correct |
2 ms |
744 KB |
n = 8 |
13 |
Correct |
2 ms |
744 KB |
n = 8 |
14 |
Correct |
2 ms |
744 KB |
n = 8 |
15 |
Correct |
2 ms |
744 KB |
n = 8 |
16 |
Correct |
3 ms |
744 KB |
n = 8 |
17 |
Correct |
3 ms |
744 KB |
n = 8 |
18 |
Correct |
2 ms |
744 KB |
n = 8 |
19 |
Correct |
2 ms |
744 KB |
n = 3 |
20 |
Correct |
2 ms |
744 KB |
n = 7 |
21 |
Correct |
3 ms |
744 KB |
n = 8 |
22 |
Correct |
3 ms |
744 KB |
n = 8 |
23 |
Correct |
2 ms |
744 KB |
n = 8 |
24 |
Correct |
2 ms |
744 KB |
n = 8 |
25 |
Correct |
2 ms |
744 KB |
n = 8 |
26 |
Correct |
2 ms |
744 KB |
n = 8 |
27 |
Correct |
2 ms |
744 KB |
n = 8 |
28 |
Correct |
3 ms |
744 KB |
n = 8 |
29 |
Correct |
95 ms |
8464 KB |
n = 16 |
30 |
Correct |
103 ms |
8464 KB |
n = 16 |
31 |
Correct |
100 ms |
8576 KB |
n = 16 |
32 |
Correct |
85 ms |
8576 KB |
n = 16 |
33 |
Correct |
101 ms |
8576 KB |
n = 16 |
34 |
Correct |
107 ms |
8576 KB |
n = 16 |
35 |
Correct |
109 ms |
8576 KB |
n = 16 |
36 |
Correct |
45 ms |
8576 KB |
n = 15 |
37 |
Correct |
3 ms |
8576 KB |
n = 8 |
38 |
Correct |
89 ms |
8576 KB |
n = 16 |
39 |
Correct |
116 ms |
8576 KB |
n = 16 |
40 |
Correct |
3 ms |
8576 KB |
n = 9 |
41 |
Correct |
116 ms |
8576 KB |
n = 16 |
42 |
Correct |
123 ms |
8576 KB |
n = 16 |
43 |
Correct |
111 ms |
8624 KB |
n = 16 |
44 |
Correct |
3 ms |
8624 KB |
n = 9 |
45 |
Correct |
33 ms |
8624 KB |
n = 15 |
46 |
Correct |
116 ms |
8624 KB |
n = 16 |
47 |
Correct |
111 ms |
8624 KB |
n = 16 |
48 |
Correct |
81 ms |
8624 KB |
n = 16 |
49 |
Correct |
156 ms |
11152 KB |
n = 199999 |
50 |
Incorrect |
156 ms |
11152 KB |
answer is not correct: 0 instead of 1 |
51 |
Halted |
0 ms |
0 KB |
- |