#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) {
return S3(s,t);
if(sz(s)<=16) return S12(s,t);
else return S3(s,t);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 2 |
2 |
Correct |
3 ms |
452 KB |
n = 2 |
3 |
Correct |
3 ms |
452 KB |
n = 2 |
4 |
Correct |
3 ms |
500 KB |
n = 2 |
5 |
Correct |
3 ms |
500 KB |
n = 2 |
6 |
Incorrect |
3 ms |
500 KB |
answer is not correct: 0 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 2 |
2 |
Correct |
3 ms |
452 KB |
n = 2 |
3 |
Correct |
3 ms |
452 KB |
n = 2 |
4 |
Correct |
3 ms |
500 KB |
n = 2 |
5 |
Correct |
3 ms |
500 KB |
n = 2 |
6 |
Incorrect |
3 ms |
500 KB |
answer is not correct: 0 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
11024 KB |
n = 199999 |
2 |
Incorrect |
147 ms |
11216 KB |
answer is not correct: 0 instead of 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
n = 2 |
2 |
Correct |
3 ms |
452 KB |
n = 2 |
3 |
Correct |
3 ms |
452 KB |
n = 2 |
4 |
Correct |
3 ms |
500 KB |
n = 2 |
5 |
Correct |
3 ms |
500 KB |
n = 2 |
6 |
Incorrect |
3 ms |
500 KB |
answer is not correct: 0 instead of 523688153 |
7 |
Halted |
0 ms |
0 KB |
- |