This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* I couldn't come up with anything except for subtasks 1-2, which can be killed
* with the standard way of finding Hamiltonian paths.
*
* After that i headed to the editorial. The method is pretty shocking to me!
*
* Time Complexity: O(2^n * n^2)
* Implementation 1
*/
#include <bits/stdc++.h>
#include "railroad.h"
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f;
ll plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = s.size();
std::vector<std::vector<ll>> min_dist(1 << n, std::vector<ll>(n, INF));
for (int i = 0; i < n; i++)
min_dist[1 << i][i] = 0;
for (int set = 1; set < (1 << n); set++) {
if ((set & (set - 1)) == 0)
continue;
for (int last = 0; last < n; last++) {
if (((set >> last) & 1) == 0)
continue;
for (int last_two = 0; last_two < n; last_two++) {
min_dist[set][last] = std::min(
min_dist[set][last],
min_dist[set ^ (1 << last)][last_two]
+ ll(std::max(t[last_two] - s[last], 0))
);
}
}
}
ll min = INF;
for (int i = 0; i < n; i++)
min = std::min(min, min_dist[(1 << n) - 1][i]);
return min;
}
# | 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... |