이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |