Submission #825297

#TimeUsernameProblemLanguageResultExecution timeMemory
825297AbdelmagedNourDungeons Game (IOI21_dungeons)C++17
63 / 100
3159 ms2097152 KiB
#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; 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(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=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<LOG;j++){ 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...