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 "railroad.h"
const int INF = 1000000001;
const int MAX_N = 16;
const int MAX_MASK = 0xFFFF;
int N, S[MAX_N], T[MAX_N];
long long dp[MAX_N + 1][MAX_MASK];
inline long long max(long long a, long long b)
{
return a > b ? a : b;
}
inline long long min(long long a, long long b)
{
return a < b ? a : b;
}
long long calc(int next, int mask)
{
if (dp[next][mask] == -1) {
int s;
if (next == MAX_N)
s = 0;
else
s = S[next];
long long v = 0x7FFFFFFFFFFFFFFF;
for (int i = 0, j = 1; i < MAX_N; ++i, j <<= 1)
if (mask & j)
v = min(v, max(0, T[i] - s) + calc(i, mask & (~j)));
dp[next][mask] = v;
}
return dp[next][mask];
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t)
{
N = (int)s.size();
if (N > 16)
return 0;
for (int i = 0; i < N; ++i) {
S[i] = s[i];
T[i] = t[i];
}
for (int i = 0; i <= N; ++i) {
dp[i][0] = 0;
for (int m = 1; m < MAX_MASK; ++m)
dp[i][m] = -1;
}
return calc(MAX_N, 0xFFFF);
}
# | 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... |