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;
const long long inf = 1e18 + 7;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
if(n <= 16){
long long dp[n][1 << n];
for(int i = 0;i<n;i++)for(int j = 0;j<(1<<n);j++)dp[i][j] = inf;
dp[0][0] = 0;
long long ans = inf;
for(int j = 0;j<(1<<n);j++){
for(int i = 0;i<n;i++){
if(j == ((1<<n)-1)){
ans = min(ans , dp[i][j]);
}
for(int k = 0;k<n;k++){
if((j & (1 << k)) == 0){
int cost = max(0 , t[i] - s[k]);
if(j == 0)cost = 0;
dp[k][j | (1 << k)] = min(dp[k][j | (1 << k)] , dp[i][j] + 1ll * cost);
}
}
}
}
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... |