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;
const int LOG = 30;
const int N = 4e5 + 5;
int n;
int mx[LOG][N];
int nxt[LOG][N];
long long d[LOG][N];
vector<int> s, p, w, l;
void init(int n_, vector<int> s_, vector<int> p_, vector<int> w_, vector<int> l_) {
n = n_;
s = s_, p = p_, w = w_, l = l_;
d[0][n] = mx[0][n] = 0;
nxt[0][n] = n;
for (int i = 0; i < n; ++i) {
nxt[0][i] = w[i];
mx[0][i] = d[0][i] = s[i];
}
for (int j = 1; j < LOG; ++j) {
for (int i = 0; i <= n; ++i) {
nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];
d[j][i] = d[j - 1][i] + d[j - 1][nxt[j - 1][i]];
mx[j][i] = max(mx[j - 1][i], mx[j - 1][nxt[j - 1][i]]);
}
}
return;
}
long long simulate(int x, int z) {
long long strength = z;
while (x != n) {
long long tmp = 0;
for (int j = LOG - 1; j >= 0; --j) {
if (mx[j][x] <= strength) {
tmp += d[j][x];
x = nxt[j][x];
}
}
strength += tmp;
if (x == n) {
return strength;
}
if (strength >= s[x]) {
strength += s[x];
x = w[x];
} else {
strength += p[x];
x = l[x];
}
}
return strength;
}
# | 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... |