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>
using namespace std;
using lint=long long;
lint plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
if(n<=16){
lint dp[1<<n][n];
for(int i=0;i<1<<n;i++){
for(int j=0;j<n;j++){
dp[i][j]=LLONG_MAX;
}
}
for(int i=0;i<n;i++){
dp[1<<i][i]=0;
}
for(int mask=1;mask<1<<n;mask++){
for(int i=0;i<n;i++){
if((mask>>i)&1){
for(int j=0;j<n;j++){
if(!((mask>>j)&1)){
int to=mask|(1<<j);
lint cost=t[i]-s[j];
if(cost<0)cost=0;
if(dp[mask][i]+cost<dp[to][j]){
dp[to][j]=dp[mask][i]+cost;
}
}
}
}
}
}
lint ans=LLONG_MAX;
for(int i=0;i<n;i++){
if(dp[(1<<n)-1][i]<ans){
ans=dp[(1<<n)-1][i];
}
}
return ans;
}
return 0;
}
# | 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... |