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>
#include "railroad.h"
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
ll plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = s.size();
vector <vector <ll>> w(n, vector <ll> (n));
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if (i == j) w[i][i] = 0;
else w[i][j] = max(0LL, (ll)t[i] - s[j]);
}
}
const ll INF = 1e18;
vector <vector <ll>> dp(n, vector <ll> (1<<n, INF));
for(int i = 0; i < n; ++i) {
dp[i][i] = 0;
dp[i][1<<i] = 0;
}
for(int mask = 1; mask < 1<<n; ++mask) {
for(int j = 0; j < n; ++j) {
if (!(mask & (1<<j))) continue;
for(int k = 0; k < n; ++k) {
if (j == k) continue;
if (!(mask & (1<<k))) continue;
dp[j][mask] = min(dp[j][mask], dp[k][mask ^ (1<<j)] + w[k][j]);
}
}
}
ll ans = INF;
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... |