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 <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#include "dungeons.h"
const int LOG=20;
typedef long long ll;
struct item{
int to;
ll earn=0;
ll mn=0;
};
struct node{
vector<item>jump;
node(){
jump.resize(LOG);
}
};
vector<vector<node>>dp;
vector<int>_s,_p,_w,_l;
int _n;
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;
dp.resize(7);
for(int z=0;z<7;z++){
auto &v=dp[z];
v.resize(_n+1);
for(int i=0;i<_n;i++){
if((1<<(4*z))>=_s[i]){
v[i].jump[0].to=_w[i];
v[i].jump[0].earn=_s[i];
v[i].jump[0].mn=1e18;
}else{
v[i].jump[0].to=_l[i];
v[i].jump[0].earn=_p[i];
v[i].jump[0].mn=_s[i];
}
}
for(int i=1;i<LOG;i++){
for(int j=0;j<_n;j++){
auto a=v[j].jump[i-1],b=v[v[j].jump[i-1].to].jump[i-1];
if(a.to==_n)v[j].jump[i]=a;
else{
v[j].jump[i].to=b.to;
v[j].jump[i].earn=a.earn+b.earn;
v[j].jump[i].mn=min(a.mn,b.mn-a.earn);
}
}
}
}
return;
}
ll simulate(int x, int Z) {
long long z=Z;
for(int j=0;j<7;j++){
while(z<(1<<(4*(j+1)))){
for(int i=LOG-1;i>=0;i--){
if(z<dp[j][x].jump[i].mn){
z+=dp[j][x].jump[i].earn;
x=dp[j][x].jump[i].to;
if(x==_n)return z;
}
}
if(z>=_s[x])z+=_s[x],x=_w[x];
else z+=_p[x],x=_l[x];
if(x==_n)return z;
}
}
return 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... |