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 x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
const ll infinity = 1e18;
const int MAX_N = 16;
ll dp[1 << MAX_N][MAX_N];
ll plan_roller_coaster(vi s, vi t) {
int n = s.size();
for (int i = 1; i < (1 << n); i++) {
for (int j = 0; j < n; j++) dp[i][j] = infinity;
if (__builtin_popcount(i) == 1) {
dp[i][__builtin_ctz(i)] = 0;
continue;
}
for (int j = 0; j < n; j++) {
if (!((i >> j) & 1)) continue;
int mask = i ^ (1 << j);
for (int k = 0; k < n; k++) {
chkmin(dp[i][j], dp[mask][k] + max(0, t[k] - s[j]));
}
}
}
ll ans = infinity;
for (int i = 0; i < n; i++) chkmin(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... |