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 "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define debug(...) //ignore
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
int n;
vi s, p, w, l;
ll LG = 25;
struct T {
int node = 0;
ll gain = 0;
ll need_strength = 0;
};
T f(T a, T b) {
T res;
res.node = b.node;
res.gain = a.gain + b.gain;
res.need_strength = max(a.need_strength, b.need_strength - a.gain);
return res;
}
vector<vector<T>> jmp;
void ini() {
jmp.assign(LG, vector<T>(n+1));
rep(i,0,n) jmp[0][i] = T{w[i], ll(s[i]), ll(s[i])};
jmp[0][n] = T{n, ll(0), ll(0)};
rep(k,1,LG) rep(i,0,n+1) jmp[k][i] = f(jmp[k-1][i], jmp[k-1][jmp[k-1][i].node]);
}
ll sim(int x, ll z) {
if(x == n) return z;
for(int k = LG; k--;) {
if(x == n) return z;
auto v = jmp[k][x];
if(z >= v.need_strength) {
z += v.gain;
x = v.node;
}
}
if(x == n) return z;
assert(z < s[x]); // we loose
return sim(l[x], z+p[x]);
}
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { ::n = n; ::s = s; ::p = p; ::w = w; ::l = l; ini(); return; }
ll simulate(int x, int z) { return sim(x,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... |