# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
574466 | Elias | Roller Coaster Railroad (IOI16_railroad) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#ifndef _DEBUG
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include "railroad.h"
#endif
using namespace std;
int64_t plan_roller_coaster(vector<int> s, vector<int> t)
{
int n = s.size();
vector<vector<int>> dp((1 << n) + 1, vector<int>(n, INT32_MAX));
dp[0][0] = 0;
for (int i = 0; i < n; i++)
{
dp[1 << i][i] = 0;
}
for (int bits = 1; bits < (1 << n) + 1; bits++)
for (int i = 0; i < n; i++)
{
if (bits & (1 << i) == 0)
continue;
for (int j = 0; j < n; j++)
{
if (i == j || bits & (1 << j) == 0)
continue;
dp[bits][i] = min(dp[bits][i], dp[bits ^ (1 << i)][j] + max(t[j] - s[i], 0));
}
}
return *min_element(dp[(1 << n) - 1].begin(), dp[(1 << n) - 1].end());
}