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;
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5+10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
ll dp[16][65540];
long long plan_roller_coaster(vector<int> s, vector<int> t) {
int n=(int)s.size();
for(int i=0;i<n;i++)
for(int j=0;j<(1<<n);j++)
dp[i][j]=LINF;
dp[0][0]=0;
for(int i=1;i<(1<<n);i++){
for(int j=0;j<n;j++){
if(!(i&(1<<j))) continue;
int curr=(i^(1<<j));
if(curr==0) dp[j][i]=0;
else{
for(int k=0;k<n;k++){
if(!(curr&(1<<k))) continue;
dp[j][i]=min(dp[j][i], dp[k][curr]+max((ll)t[k]-(ll)s[j], 0ll));
}
}
}
}
ll ans=LINF;
for(int i=0;i<n;i++) ans=min(ans, dp[i][(1<<n)-1]);
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... |