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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
#define ffor(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define fford(i, a, b) for (ll i = (a); i > (ll)(b); i--)
#define rep(i, n) ffor(i, 0, n)
#define forin(x, a) for (auto &x: a)
#define all(a) a.begin(), a.end()
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
ll res = 1LL << 62;
vii used(n);
ll curr = 0;
function<void(int)> dfs;
dfs = [&](int speed) {
if (curr > res) {
return;
}
bool found = false;
rep(i, n) {
if (!used[i]) {
found = true;
used[i] = true;
curr += max(0, speed - s[i]);
dfs(t[i]);
curr -= max(0, speed - s[i]);
used[i] = false;
}
}
if (!found) {
res = min(res, curr);
}
};
dfs(1);
return res;
}
# | 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... |