# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134809 | MAMBA | 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 "railroad.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for (int i = j; i < (int)k; i++)
typedef long long ll;
ll dp[1 << 17][17];
void smin(ll &a, ll b) {
if (b < a) a = b;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
rep(mask , 1 , (1 << n)) {
rep(r , 0, n ) {
dp[mask][r] = 1e18;
if (__builtin_popcount(mask) == 1) {
if ((mask >> r) & 1)
dp[mask][r] = 0;
continue;
}
if (!((mask >> r) & 1))
continue;
rep(i , 0 , n) {
if (i != r && (mask >> i) & 1)
smin(dp[mask][r] , dp[mask ^ (1 << r)][i] + max(0 , t[i] - s[r]));
}
}
}
ll res = 1e18;
rep(i , 0 , n) {
// cout << dp[(1 << n) - 1][i] << endl;
smin(res , dp[(1 << n) - 1][i]);
}