Submission #825289

#TimeUsernameProblemLanguageResultExecution timeMemory
825289AbdelmagedNourDungeons Game (IOI21_dungeons)C++17
63 / 100
3226 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 cost=0; ll mx=0; }; struct node{ vector<item> a; node(){ a.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].a[0].to=_w[i]; v[i].a[0].cost=_s[i]; v[i].a[0].mx=1e18; } else{ v[i].a[0].to=_l[i]; v[i].a[0].cost=_p[i]; v[i].a[0].mx=_s[i]; } } for(int i=1;i<LOG;i++){ for(int j=0;j<_n;j++){ auto a=v[j].a[i-1],b=v[v[j].a[i-1].to].a[i-1]; if(a.to==_n){ v[j].a[i]=a; } else{ v[j].a[i].to=b.to; v[j].a[i].cost=a.cost+b.cost; v[j].a[i].mx=min(a.mx,b.mx-a.cost); } } } } 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].a[i].mx){ z+=dp[j][x].a[i].cost; x=dp[j][x].a[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...