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 <iostream>
#include <algorithm>
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
long long int dp[100010][20] = { 0 };
dp[0][0] = 0;
int val = 1 << n;
for (int x = 1; x < val; ++x)
{
for (int j = 0; j < n; ++j)
{
dp[x][j] = 1e15;
}
}
for (int x = 1; x < val; ++x)
{
int bitNr = __builtin_popcount(x);
if (bitNr == 1)
{
for (int j = 0; j < n; ++j)
{
if (x & (1 << j))
{
dp[x][j] = 0;
break;
}
}
}
else
{
for (int j = 0; j < n; ++j)
{
if (x & (1 << j))
{
int newNr = x ^ (1 << j);
for (int k = 0; k < n; ++k)
{
if (newNr & (1 << k))
{
dp[x][j] = std::min(dp[x][j], dp[newNr][k] + std::max(0, t[k] - s[j]));
}
}
}
}
}
}
/*
for (int x = 1; x < val; ++x)
{
for (int j = 0; j < n; ++j)
{
std::cout << x << " " << j << " " << dp[x][j] << "\n";
}
}
*/
--val;
long long int ans = 1e15;
for (int i = 0; i < n; ++i)
{
ans = std::min(ans, dp[val][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... |