Submission #429083

#TimeUsernameProblemLanguageResultExecution timeMemory
429083TangentRoller Coaster Railroad (IOI16_railroad)C++17
11 / 100
2058 ms8648 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...