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 <bits/stdc++.h>
#include "railroad.h"
//#include "grader.cpp"
using namespace std;
typedef long long ll;
const ll inf=(1ll<<61);
const int MX=17;
ll dp[(1<<MX)][MX],S[MX],T[MX];
int n;
ll DP(ll mask,ll last){
if(mask+1==(1<<n))return 0;
ll &ret=dp[mask][last];if(ret!=-1)return ret;
ret=inf;
for(int i=0;i<n;i++){
if(mask&(1<<i))continue;
if(last==n){
ret=min(ret,DP(mask|(1<<i) , i));
}
else {
ret=min(ret,DP(mask|(1<<i) , i) + max(0ll,T[last] - S[i]));
}
}
return ret;
}
ll plan_roller_coaster(vector<int> s, vector<int> t) {
n = (int) s.size();
for(int i=0;i<n;i++)S[i]=s[i],T[i]=t[i];
memset(dp,-1,sizeof(dp));
return DP(0,n);
}
# | 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... |