Submission #438250

#TimeUsernameProblemLanguageResultExecution timeMemory
438250ApiramDungeons Game (IOI21_dungeons)C++17
0 / 100
3170 ms15288 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; int nnn; vector<int>sss,ppp,www,lll; vector<long long>winning_path; vector<int>adj[400001]; void gen(void); void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) { nnn=nn; sss=ss,ppp=pp,www=ww,lll=ll; for(int i = 0 ; i < nnn ; i++) { adj[www[i]].push_back(i); } gen(); } void gen(void) { vector<bool>vis(nnn+1,false); winning_path.resize(nnn+1); winning_path[nnn]=0; queue<int>q; q.push(nnn); long long cnt=0; while(!q.empty()) { int sz = q.size(); while(sz--) { int node = q.front(); q.pop(); vis[node]=true; winning_path[node]=cnt; for(auto z : adj[node]) { if(!vis[z]) { q.push(z); } } } cnt++; } } long long simulate(int x, int zz) { vector<pair<bool,long long>>v(nnn+1,{false,0}); vector<long long>steps(nnn+1,0),seq; long long curr=0, len=0; long long z=zz; while(true) { if(v[x].first) { long long ans = (sss[x]-z)/(curr-v[x].second); z+=ans*(curr-v[x].second); int left=steps[x], right=len-1, use=x; while(left <= right) { int mid = (left+right)/2; if(z+(v[seq[mid]].second-v[x].second) >= sss[x]) { use=mid; right=mid-1; } else { left=mid+1; } } z+=v[seq[use]].second - v[x].second; x=seq[use+1]; } if(x==nnn) return z; if(z >= sss[x]) { long long mul = sss[x]*winning_path[x]; return z+mul; } v[x].first=true,v[x].second=curr; z+=ppp[x], curr+=ppp[x]; steps[x]=len; seq.push_back(x); x=lll[x]; len++; } }
#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...