This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
#include "railroad.h"
ll plan_roller_coaster(vector<int> s_g, vector<int> t_g) {
vi s, t;
int N = (int)(s_g.size());
for (int i = 0; i < N; i++) {
s.pb(s_g[i]);
t.pb(t_g[i]);
}
vector<vi> dp(1 << N, vi(N, 1e18));
vector<vi> allc(N + 1);
for (int i = 0; i < (1 << N); i++) {
int cnt = 0;
for (int j = 0; j < N; j++) {
if (i & (1 << j))
cnt++;
}
allc[cnt].pb(i);
}
/* cout<<"allc: "<<endl;
for (int i = 0; i <= N; i++) {
cout<<i<<": ";
for (int x : allc[i])
cout<<x<<" ";
cout<<endl;
}*/
for (int i = 0; i < N; i++) {
dp[1 << i][i] = 0;
}
for (int i = 2; i <= N; i++) { // count reached
for (ll x : allc[i]) { // bitmask
for (int j = 0; j < N; j++) { // last val
if ((x & (1 << j)) == 0)
continue;
// last is j
for (int k = 0; k < N; k++) { // before last
if (k != j && ((x & (1 << k)) != 0)) {
dp[x][j] = min(dp[x][j], dp[x ^ (1 << j)][k] + max(t[k] - s[j], 0LL));
/* cout<<"x, j, k: "<<x<<" "<<j<<" "<<k<<endl;
cout<<"have "<<(x & (1 << j))<<", "<<(x & (1 << k))<<endl;
cout<<"also "<<t[k]<<", "<<s[j]<<endl;*/
}
}
}
}
}
/* cout<<"dp: "<<endl;
for (int i = 0; i < (1 << N); i++) {
for (int j = 0; j < N; j++) {
if (dp[i][j] != 1e18)
cout<<dp[i][j]<<" ";
else
cout<<"- ";
}
cout<<endl;
}*/
ll minimum = 1e18;
for (int i = 0; i < N; i++) {
minimum = min(minimum, dp[(1 << N) - 1][i]);
}
return minimum;
}
# | 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... |