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;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = s.size();
long long dp[1<<n][n];
for(int i = 0;i < n;i++) dp[(1<<n)-1][i] = 0;
for(int b = (1<<n)-2;b;b--){
for(int j = 0;j < n;j++){
if(!((b>>j)&1)) continue;
dp[b][j] = LONG_LONG_MAX;
for(int k = 0;k < n;k++){
if((b>>k)&1) continue;
dp[b][j] = min(dp[b][j], dp[b|(1<<k)][k]+max(0, t[j]-s[k]));
}
}
}
long long ans = LONG_LONG_MAX;
for(int i = 0;i < n;i++) ans = min(ans, dp[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... |