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 int MAXN=20;
const ll INF=1e18;
ll dist[MAXN][MAXN];
ll dp[MAXN][(1<<MAXN)];
int n;
ll fazdp(int cur, int mask) {
if(dp[cur][mask]!=-1) return dp[cur][mask];
dp[cur][mask]=INF;
for(int viz=0; viz<n; viz++) {
if(viz==cur) continue;
if((mask&(1<<viz))==0) continue;
ll val=fazdp(viz, mask^(1<<cur))+dist[viz][cur];
dp[cur][mask]=min(dp[cur][mask], val);
}
// printf("%d %d >> %lld\n", cur, mask, dp[cur][mask]);
return dp[cur][mask];
}
ll plan_roller_coaster(vector<int> s, vector<int> t) {
n = (int) s.size();
memset(dp, -1, sizeof(dp));
for(int i=0; i<n; i++) dp[i][(1<<i)]=0;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
dist[i][j]= (t[i]<=s[j]) ? 0 : t[i]-s[j];
if(i==j) dist[i][j]=0;
// printf("d %d %d > %lld\n", i, j, dist[i][j]);
}
}
ll respf=INF;
for(int i=0; i<n; i++) respf=min(respf, fazdp(i, (1<<n)-1));
return respf;
}
# | 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... |