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>
using namespace std;
using ll = long long;
template<class T> bool cmin(T &i, T j) { return i > j ? i=j,1:0; }
template<class T> bool cmax(T &i, T j) { return i < j ? i=j,1:0; }
const int N=16;
const ll inf = 1e18;
ll dp[1<<N][N];
int n;
ll plan_roller_coaster(vector<int> s,vector<int> t) {
n = int(s.size());
memset(dp,0x3f,sizeof(dp));
for (int i=0;i<n;i++) {
dp[1<<i][i]=0LL;
}
for (int mask=1;mask<(1<<n);mask++) {
for (int i=0;i<n;i++) {
if (mask&(1<<i)) {
// possible endpoint
if (dp[mask][i]<=inf) {
continue;
}
for (int j=0;j<n;j++) {
if (i!=j&&mask&(1<<j)) {
cmin(dp[mask][i],
dp[mask^(1<<i)][j]+max(0,t[j]-s[i]));
}
}
}
}
}
ll ans = inf;
for (int i=0;i<n;i++) {
cmin(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... |