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;
typedef long long ll;
const ll INF = 1e18;
ll plan_roller_coaster(vector<int> s, vector<int> t) {
int n = (int)s.size();
vector<vector<ll>> dp(1<<n, vector<ll>(n));
for(int msk=1; msk < (1<<n); msk++){
if(__builtin_popcount(msk) == 1) continue;
for(int i = 0; i < n; i++){
if(!(msk & (1<<i))) continue;
dp[msk][i] = INF;
int m = msk^(1<<i);
for(int j = 0; j < n; j++){
if(!(m & (1<<j))) continue;
dp[msk][i] = min(dp[msk][i], dp[m][j] + max(0, t[j]-s[i]));
}
}
}
ll ans = INF;
for(int i = 0; i < n; i++) ans = min(ans, dp[(1<<n)-1][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... |