이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
const int oo = 1000 * 1000 * 1000 + 7;
int N, A[16][2]; ll DP[16][(1 << 16)];
ll solve(int i, int mask) {
if(__builtin_popcount(mask) == N)
return 0;
if(DP[i][mask] != -1) return DP[i][mask];
ll best = 1000000000000000007;
for(int l = 0; l < N; l++) {
if(mask & (1 << l)) continue;
ll cur = max(0, A[i][1] - A[l][0]);
best = min(best, cur + solve(l, mask | (1 << l)));
}
return DP[i][mask] = best;
}
long long plan_roller_coaster(vector<int> S, vector<int> T) {
N = (int)S.size();
memset(DP, -1, sizeof DP);
ll res = 1000000000000000007;
for(int l = 0; l < N; l++)
A[l][0] = S[l], A[l][1] = T[l];
for(int l = 0; l < N; l++)
res = min(res, solve(l, (1 << l)));
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... |