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 INF = 1e8;
vector<int> s,p,w,l;
vector<vector<int>> lift;
vector<vector<long long>> liftcost;
vector<long long> bestans;
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;
lift = vector(n+1,vector(24,0));
liftcost = vector(n+1,vector(24,0ll));
bestans = vector(n+1,0ll);
for(int i=n-1;i>=0;i--){
bestans[i]=bestans[w[i]]+s[i];
lift[i][0] = l[i];
liftcost[i][0] = p[i];
}
liftcost[n][0]=INF;
lift[n][0]=n;
for(int bit=1;bit<24;bit++){
for(int i=0;i<=n;i++){
lift[i][bit]=lift[lift[i][bit-1]][bit-1];
liftcost[i][bit]=liftcost[i][bit-1]+liftcost[lift[i][bit-1]][bit-1];
}
}
return;
}
long long simulate(int x,int z){
for(int bit=23;bit>=0;bit--){
if(z+liftcost[x][bit]<s[0]){
z+=liftcost[x][bit];
x=lift[x][bit];
}
}
if(x==n)return z;
if(z<s[0]){
z+=liftcost[x][0];
x = lift[x][0];
}
return z+bestans[x];
}
# | 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... |