This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "railroad.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll inf = 17 , MX = 1e18+9;
ll n,s[inf],t[inf],dp[(1<<inf)][inf];
ll solve(ll mask,ll cur){
if(mask == (1ll<<n)-1ll)
return 0;
ll &ret = dp[mask][cur];
if(ret != -1)
return ret;
ret = MX;
for(int i=0;i<n;i++)
if(!(mask & (1ll<<i) ) )
ret = min(ret , solve( mask | (1ll<<i) , i ) + max( 0ll , t[cur] - s[i] ) );
return ret;
}
long long plan_roller_coaster(vector<int> S, vector<int> T) {
ll ans = MX;
n = (ll) S.size();
for(ll i=0;i<n;i++)
s[i] = S[i],t[i] = T[i];
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++)
ans = min( ans , solve((1<<i),i) );
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |