This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Pantyhose(black) + glasses = infinity
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"
const int64_t INF = 1e18;
int n;
vector<pair<int, int> > a;
int64_t f[1<<16][16];
int64_t dp(int mask, int last) {
if (__builtin_popcount(mask)==n)
return 0;
if (f[mask][last]>-1)
return f[mask][last];
int64_t res = INF;
for (int i=0; i<n; ++i) {
if (((mask>>i) & 1)==0) {
int new_mask = mask | (1<<i);
// if (mask==11 && last==1 && i==2)
// debug();
res = min(res, dp(new_mask, i) + max(0, a[last].second - a[i].first));
}
}
return f[mask][last] = res;
}
int64_t plan_roller_coaster(vector<int> s, vector<int> t) {
n = s.size();
a.resize(n);
for (int i=0; i<n; ++i)
a[i] = {s[i], t[i]};
sort(a.begin(), a.end());
if (n<=16) {
memset(f, -1, sizeof(f));
// debug(dp(1, 0));
int64_t res = INF;
for (int i=0; i<n; ++i)
res = min(res, dp(1<<i, i));
return res;
}
}
Compilation message (stderr)
railroad.cpp: In function 'int64_t plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:57:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |