#include <bits/stdc++.h>
#include "dungeons.h"
#define ent '\n'
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 12;
int s[maxn], p[maxn], w[maxn], l[maxn];
ll sum[10][26][maxn], mn[10][26][maxn];
int up[10][26][maxn];
ll pw[maxn];
int n;
void init(int N, vector<int> S, vector<int> P, vector<int> W, vector<int> L) {
n = N;
pw[0] = 1;
for(int i = 1; i < 9; i++) {
pw[i] = pw[i - 1] * 8;
}
for(int i = 0; i < n; i++) {
s[i] = S[i], p[i] = P[i];
w[i] = W[i], l[i] = L[i];
}
for(int b = 0; b < 9; b++) {
up[b][0][n] = n;
mn[b][0][n] = -1e18;
for(int i = 0; i < n; i++) {
if(s[i] < pw[b]) {
up[b][0][i] = w[i];
mn[b][0][i] = 1e18;
sum[b][0][i] = s[i];
}
else {
up[b][0][i] = l[i];
mn[b][0][i] = s[i];
sum[b][0][i] = p[i];
}
}
for(int k = 1; k < 26; k++) {
for(int i = 0; i <= n; i++) {
up[b][k][i] = up[b][k - 1][up[b][k - 1][i]];
mn[b][k][i] = min(mn[b][k - 1][i] * 1ll, max(0ll, mn[b][k - 1][up[b][k - 1][i]] - sum[b][k - 1][i]));
sum[b][k][i] = sum[b][k - 1][i] + sum[b][k - 1][up[b][k - 1][i]];
}
}
}
}
ll simulate(int x, int val) {
ll cur = val;
while(x < n) {
int b = 0;
while(b + 1 < 9 && cur >= pw[b + 1] - 1) {
b++;
}
for(int k = 25; k >= 0; k--) {
if(mn[b][k][x] > cur) {
cur += sum[b][k][x];
x = up[b][k][x];
}
}
if(x == n) break;
if(cur >= s[x]) {
cur += s[x];
x = w[x];
}
else {
cur += p[x];
x = l[x];
}
}
return cur;
}
# | 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... |