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>
#define N 16
using namespace std;
long long dp[(1<<N)][N];
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
for(int i = 0;i<(1<<n);i++){
for(int j = 0;j<n;j++){
dp[i][j] = 2e18;
}
}
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 & (1<<i)))continue;
for(int j = 0;j<n;j++){
if(mask & (1<<j))continue;
dp[mask + (1<<j)][j] = min(dp[mask + (1<<j)][j],dp[mask][i] + max(0,t[i] - s[j]));
}
//cout << mask << " " << i << " " << dp[mask][i] << endl;
}
}
long long ret = 2e18;
for(int i = 0;i<n;i++){
ret = min(ret,dp[(1<<n)-1][i]);
}
return ret;
}
# | 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... |