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/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__);
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using ll = long long;
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
ll plan_roller_coaster(vector<int> s, vector<int> t) {
int n = sz(s);
long dp[1 << n][n];
memset(dp, 0x3f, sizeof(dp));
for (int i = (1 << n) - 1; i >= 0; i--) {
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
continue;
} else if ((i | (1 << j)) == (1 << n) - 1) {
dp[i][j] = 0;
continue;
}
for (int k = 0; k < n; k++) {
if (j != k && !((i >> k) & 1)) {
dp[i][j] = min(dp[i][j],
dp[i | (1 << j)][k] + max(0, t[j] - s[k]));
}
}
}
}
return *min_element(dp[0], dp[0] + n);
}
# | 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... |