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"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
typedef long long llong;
const int MAXB = (1 << 16);
const int MAXN = 16;
int n;
int s[MAXN];
int t[MAXN];
llong dp[MAXB][MAXN];
bool bl[MAXB][MAXN];
llong f(int mask, int last)
{
if (__builtin_popcount(mask) == n)
{
return 0;
}
if (bl[mask][last])
{
return dp[mask][last];
}
bl[mask][last] = true;
dp[mask][last] = 1e18;
for (int i = 0 ; i < n ; ++i)
{
if (mask & (1 << i))
{
continue;
}
dp[mask][last] = std::min(dp[mask][last], f(mask | (1 << i), i) + std::max(0, t[last] - s[i]));
}
return dp[mask][last];
}
llong plan_roller_coaster(std::vector<int> S, std::vector<int> T)
{
n = S.size();
for (int i = 0 ; i < n ; ++i)
{
s[i] = S[i];
t[i] = T[i];
}
llong ans = 1e18;
for (int i = 0 ; i < n ; ++i)
{
ans = std::min(ans, f(1 << i, 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... |