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>
/*#pragma GCC optimize("03")
#pragma GCC target("avx,avx2")
#pragma GCC optimeze("unroll-loops") */
#define inf 10000000000000000
#define ll long long
#include "railroad.h"
using namespace std;
int n;
ll dp[16][16][1 << 16],cost[16][16];
ll plan_roller_coaster(vector<int> a, vector<int> b) {
n = a.size();
for (int i = 0; i < n; i++) {
for (int j = 0;j < n; j++) {
if (b[i] > a[j] && j != i) cost[i][j] = b[i] - a[j];
fill(dp[i][j],dp[i][j] + (1 << n),inf);
}
dp[i][i][(1 << i)] = 0;
}
for (int mask = 1; mask < (1 << n); mask++)
for (int i = 0; i < n; i++) {
if ((1 << i) & mask) {
for (int j = 0; j < n; j++) {
if ( ((1 << j) & mask) && j != i) {
for (int e = 0; e < n; e++) {
if (e != j && dp[i][j][mask] > dp[i][e][mask^(1<<j)] + cost[e][j])
dp[i][j][mask] = dp[i][e][mask^(1<<j)] + cost[e][j];
}
}
}
}
}
ll ans = inf;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
ans = min(ans,dp[i][j][(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... |