This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Ignut
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18 + 123;
const int inf = 1e9 + 123;
const int N = 16;
ll dp[1 << N][N];
ll plan_roller_coaster(vector<int> s, vector<int> t) {
int n = s.size();
for (int i = 0; i < 1 << n; i ++)
for (int j = 0; j < n; j ++)
dp[i][j] = INF;
for (int i = 0; i < n; i ++)
dp[1 << i][i] = 0;
vector<pair<int, int>> lst;
for (int mask = 1; mask + 1 < 1 << n; mask ++) {
lst.push_back({__builtin_popcount(mask), mask});
}
sort(lst.begin(), lst.end());
for (auto [popcnt, mask] : lst) {
for (int i = 0; i < n; i ++) {
if (!(mask & (1 << i))) continue;
for (int j = 0; j < n; j ++) {
if (mask & (1 << j)) continue;
dp[mask | (1 << j)][j] = min(dp[mask | (1 << j)][j], dp[mask][i] + max(0, t[i] - s[j]));
}
}
}
ll res = INF;
for (int i = 0; i < n; i ++)
res = min(res, dp[(1 << n) - 1][i]);
return res;
}
/*
*/
# | 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... |