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 pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using vi = vector<int>;
using ll = long long;
int n, tot, mxS;
const int mxN = (int)4e5+10;
const int mxLg = 25;
vi s, p, l, w;
struct jmpNode{
int loc;
ll totSt;
int mxSt;
jmpNode(int x=-1, ll y=0){
loc=x, totSt=y; mxSt=y;
}
};
jmpNode jmp[mxLg][mxN];
void init(int N, vi _s, vi _p, vi _w, vi _l) {
n = N;
for(auto u : _s) s.pb(u);
for(auto u : _p) p.pb(u);
for(auto u : _w) w.pb(u);
for(auto u : _l) l.pb(u);
mxS = max(*max_element(all(s)),*max_element(all(p)));
for(int i = 0; i < n; i++)
jmp[0][i] = jmpNode(w[i],s[i]);
jmp[0][n]= jmpNode(n,0);
for(int i = 1; i < mxLg; i++){
for(int j = 0; j < n; j++){
jmp[i][j].loc = jmp[i-1][jmp[i-1][j].loc].loc;
jmp[i][j].totSt = jmp[i-1][j].totSt+jmp[i-1][jmp[i-1][j].loc].totSt;
jmp[i][j].mxSt = max(jmp[i-1][j].mxSt,jmp[i-1][jmp[i-1][j].loc].mxSt);
}
jmp[i][n] = jmpNode(n,0);
}
}
ll simulate(int x, int z) {
ll strength = z;
while(x!=n and strength<mxS){
ll curStr = strength;
for(int i = mxLg-1; i>=0 and strength<mxS; i--){
if(jmp[i][x].loc!=n and jmp[i][x].mxSt<=curStr)
strength+=jmp[i][x].totSt, x=jmp[i][x].loc;
}
if(s[x]>strength) strength+=p[x], x=l[x];
else strength+=s[x], x=w[x];
}
for(int i = mxLg-1; i>=0; i--)
if(jmp[i][x].loc!=n)
strength+=jmp[i][x].totSt, x=jmp[i][x].loc;
if(x!=n) strength+=jmp[0][x].totSt, x=jmp[0][x].loc;
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... |