This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define N 400001
ll n;
ll l[N][19];
ll w[N][19];
ll sl[N][19];
ll sw[N][19];
ll rw[N][19];
ll rl[N][19];
void init(int m,vector<int> s,vector<int> p,vector<int> W,vector<int> L){
n=m;
w[n][0]=n;
rw[n][0]=1e17;
for(int i=0;i<n;i++){
l[i][0]=L[i];
w[i][0]=W[i];
sl[i][0]=p[i];
sw[i][0]=s[i];
rl[i][0]=s[i]+p[i];
rw[i][0]=s[i]+s[i];
}
for(int j=0;j<18;j++){
for(int i=0;i<=n;i++){
l[i][j+1]=l[l[i][j]][j];
w[i][j+1]=w[w[i][j]][j];
sl[i][j+1]=sl[i][j]+sl[l[i][j]][j];
sw[i][j+1]=sw[i][j]+sw[w[i][j]][j];
rl[i][j+1]=min(rl[l[i][j]][j],rl[i][j]+sl[l[i][j]][j]);
rw[i][j+1]=max(rw[w[i][j]][j],rw[i][j]+sw[w[i][j]][j]);
}
}
}
ll simulate(int x,int z){
int t=0;
ll p=x;
ll q=z;
while(p!=n){
if(t==1){
for(int j=18;j>=0;j--){
if(rw[p][j]<=sw[p][j]+q){
q+=sw[p][j];
p=w[p][j];
}
}
}
else{
for(int j=18;j>=0;j--){
if(rl[p][j]>sl[p][j]+q){
q+=sl[p][j];
p=l[p][j];
}
}
}
t=(t+1)%2;
}
return q;
}
# | 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... |