#include "dungeons.h"
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
int N;
vector<int> s,p,l;
vector<vector<int>> nxt,mx,w;
const int LOG=26;
void init(signed n, std::vector<signed> S, std::vector<signed> P, std::vector<signed> W, std::vector<signed> L) {
N=n;
s.resize(N+1);
p.resize(N);
l.resize(N+1);
w.resize(N+1,vector<int>(LOG,N));
nxt.resize(N+1,vector<int>(LOG,0));
mx.resize(N+1,vector<int>(LOG,0));
w[N][0]=N;
s[N]=0;
for (int i = 0; i < n; i++)
{
s[i]=S[i];
p[i]=P[i];
w[i][0]=W[i];
l[i]=L[i];
nxt[i][0]=s[i];
mx[i][0]=s[i];
}
for (int j = 1; j < LOG; j++)
{
for (int i = 0; i < N; i++)
{
w[N][j]=N;
w[i][j]=w[w[i][j-1]][j-1];
nxt[i][j]=nxt[i][j-1]+nxt[w[i][j-1]][j-1];
mx[i][j]=max(mx[i][j-1],mx[w[i][j-1]][j-1]-nxt[i][j-1]);
}
}
return;
}
long long simulate(signed x, signed z) {
int cs=z;
int u=x;
while(u!=N){
if(s[u]>cs) {
cs+=p[u];
u=l[u];
continue;
}
int v=u;
for (int j = LOG-1; j >= 0; j--)
{
if(mx[v][j]-cs>0) continue;
cs+=nxt[v][j];
v=w[v][j];
if(v==N) return cs;
}
cs+=p[u];
u=l[u];
}
return cs;
}
# | 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... |