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>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
const int N = 2e5+5;
int am[16][16];
ll res[16][(1<<16)+5];
ll dp(int i, int bm) {
if (bm == 0) return 0;
if (~res[i][bm]) return res[i][bm];
res[i][bm] = 1e18;
int x = bm;
while (x) {
int lso = x&-x;
int j = __builtin_ctz(lso);
res[i][bm] = min(res[i][bm], am[i][j] + dp(j, bm ^ lso));
x -= lso;
}
//cout << i << " " << bm << " :: " << res[i][bm] << endl;
return res[i][bm];
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
FOR(i, 0, n-1) {
FOR(j, 0, n-1) {
am[i][j] = max(0, t[i]-s[j]);
}
}
memset(res, -1, sizeof res);
ll ans = 1e18;
FOR(i, 0, n-1) ans = min(ans, dp(i, ((1<<n)-1)^(1<<i)));
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... |