이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
#define A(a) (a).begin(), (a).end()
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define F(i, l, r) for (ll i = (l); i < (r); ++i)
#define FD(i, l, r) for (ll i = (l); i > (r); --i)
#define K first
#define V second
const ll NN = 50010;
const ll SN = 0;
ll n;
ll s[NN], p[NN], w[NN], l[NN];
bool big[NN];
pl ans[NN]; // {minimum strength needed to clear to root, bonus delta }
void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) {
    n = _n;
    copy(A(_s), s);
    copy(A(_p), p);
    copy(A(_w), w);
    copy(A(_l), l);
    // precomp ans
    FD(i, n-1, -1) {
        ans[i].K = max(s[i], ans[w[i]].K - s[i]);   
        ans[i].V = ans[w[i]].V + s[i];
    }
}
long long simulate(int _x, int _z) {
    ll x = _x, z = _z;
    while (x - n and z <= SN) {
        if (z >= s[x]) z += s[x], x = w[x];
        else z += p[x], x = l[x];
    }
    if (x == n) return z;
    // TODO: implement some kind of bsearch dictating how far to go 
    // dummy code 
    {
        while (x - n and ans[x].K > z) {
            if (z >= s[x]) z += s[x], x = w[x];
            else z += p[x], x = l[x];
        }
        if (x == n) return z;
        return ans[x].V + z;
    }
}
| # | 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... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |