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>
#define long long long
using namespace std;
const int N = 16;
int n;
vector<int> s, t;
long dp[N][1<<N];
long solve(int u, int bit) {
if(dp[u][bit] != -1) return dp[u][bit];
if((bit ^ (1 << u)) == 0) return dp[u][bit] = 0;
dp[u][bit] = 1e18;
for(int i = 0; i < n; ++i) if(i != u && ((bit >> i) & 1)) {
long val = (t[i] > s[u] ? (t[i] - s[u]) : 0) + solve(i, bit ^ (1 << u));
dp[u][bit] = min(dp[u][bit], val);
}
return dp[u][bit];
}
long plan_roller_coaster(vector<int> s, vector<int> t) {
n = (int)s.size();
::s = s, ::t = t;
memset(dp, -1, sizeof dp);
int bit = (1 << n) - 1;
long ans = 1e18;
for(int i = 0; i < n; ++i) ans = min(ans, solve(i, bit));
return ans;
return 0;
}
# | 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... |