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 pair<int, int> pii;
typedef long long ll;
const int MAXN = 16;
const int MAXM = 1e9+5;
const ll inf = (ll)MAXN*MAXM;
int nxt[MAXN];
ll dp[MAXN+1][1<<MAXN]; // thing that just happened
int n;
ll plan_roller_coaster(vector<int> s, vector<int> t) {
t.push_back(1);
n = s.size();
for (int i = 0; i < n; i++) {
dp[i][0] = 0;
}
for (int mask = 1; mask < (1<<n); mask++) {
for (int prev = 0; prev <= n; prev++) {
if ((1<<prev)&mask) continue;
// if (prev == n && mask < (1<<n)-1) continue;
dp[prev][mask] = inf;
for (int nxt = 0; nxt < n; nxt++) {
if (((1<<nxt)&mask) == 0) continue;
dp[prev][mask] = min(dp[prev][mask], dp[nxt][mask^(1<<nxt)]+max(0, t[prev]-s[nxt]));
}
}
}
return dp[n][(1<<n)-1];
}
# | 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... |