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>
using namespace std;
using ll = long long;
constexpr ll INF = 1000000000000000000LL;
ll n, m, q, k, x, y, a, b, c;
long long plan_roller_coaster(vector<int> s, vector<int> t) {
n = (int) s.size();
if (n <= 16) {
vector< vector<ll> > dp((1 << n), vector<ll>(n, INF));
ll ans = INF;
for (int i = 1; i < (1 << n); i++) {
vector<int> v;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
v.push_back(j);
}
}
for (auto j : v) {
if (v.size() == 1) {
dp[i][j] = 0;
}
else {
for (int k = 0; k < n; k++) {
if (!((i >> k) & 1) || j == k) {
continue;
}
dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + max(0, t[k] - s[j]));
}
}
if (v.size() == n) {
ans = min(ans, dp[i][j]);
}
// cout << bitset<4>(i) << ' ' << j << ' ' << dp[i][j] << '\n';
}
}
return ans;
}
vector< pair<ll, ll> > v;
for (int i = 0; i < n; i++) {
v.push_back({t[i], s[i]});
}
sort(v.rbegin(), v.rend());
sort(s.rbegin(), s.rend());
ll e = 0;
for (int i = 0; i < n; i++) {
while (e < n && s[e] >= v[i].first) {
}
if (e - (v[i].second >= v[i].first ? 1 : 0) < i) {
return 1;
}
}
return 0;
}
Compilation message (stderr)
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:34:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
34 | if (v.size() == n) {
| ~~~~~~~~~^~~~
# | 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... |