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=25;
typedef long long ll;
struct item{
int to;
ll earn=0;
int mn=0;
};
struct node{
vector<item>jump;
node(){
jump.resize(13);
}
};
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(LOG);
for(int z=0;z<LOG;z++){
auto &v=dp[z];
v.resize(_n+1);
for(int i=0;i<_n;i++){
if((1<<z)>=_s[i]){
v[i].jump[0].to=_w[i];
v[i].jump[0].earn=_s[i];
v[i].jump[0].mn=2e9;
}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<13;i++){
for(int j=0;j<_n;j++){
//auto a=v[j].jump[i-1],b=v[a.to].jump[i-1],c=v[b.to].jump[i-1],d=v[c.to].jump[i-1];
vector<item>a;a.reserve(4);
a.push_back(v[j].jump[i-1]);
for(int k=1;k<4;k++)a.push_back(v[a.back().to].jump[i-1]);
ll sum=0,mn=1e18,to=-1;
for(int k=0;k<4;k++){
mn=min(mn,(a[k].mn==int(2e9)?ll(1e18):a[k].mn)-sum);
sum+=a[k].earn;
to=a[k].to;
if(a[k].to==_n)break;
}
v[j].jump[i].to=to;
v[j].jump[i].earn=sum;
v[j].jump[i].mn=max(min(mn,ll(2e9)),-1LL);
}
}
}
return;
}
ll simulate(int x, int Z) {
long long z=Z;
for(int j=__lg(z);j<LOG;j++){
for(int i=12;i>=0;i--){
while(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... |