Submission #981458

#TimeUsernameProblemLanguageResultExecution timeMemory
98145812345678Dungeons Game (IOI21_dungeons)C++17
100 / 100
3624 ms1913652 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=4e5+5, lx=8, kx=25; ll N, pw[20], dist[nx]; vector<int> S(nx), P(nx), W(nx), L(nx); struct edge { int out; ll cost, t; edge(int out=0, ll cost=0, ll t=0): out(out), cost(cost), t(t){} } dp[lx][nx][kx]; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { N=n; pw[0]=1; for (int i=1; i<20; i++) pw[i]=pw[i-1]*8; for (int i=0; i<n; i++) S[i]=s[i], P[i]=p[i], W[i]=w[i], L[i]=l[i]; for (int i=n-1; i>=0; i--) dist[i]=dist[w[i]]+s[i]; W[n]=L[n]=n; for (int i=0; i<lx; i++) { for (int u=0; u<=n; u++) { if (s[u]<=pw[i]) dp[i][u][0]=edge(W[u], S[u], 1e18); else dp[i][u][0]=edge(L[u], P[u], S[u]); } for (int j=1; j<kx; j++) { for (int u=0; u<=n; u++) { int v=dp[i][u][j-1].out; ll out=dp[i][v][j-1].out; ll cost=dp[i][u][j-1].cost+dp[i][v][j-1].cost; ll t=min(dp[i][u][j-1].t, dp[i][v][j-1].t-dp[i][u][j-1].cost); dp[i][u][j]=edge(out, cost, t); } } } } long long simulate(int x, int z) { ll cur=z, st=0; while (x!=N&&cur<1e7) { //cout<<"debug "<<x<<' '<<cur<<' '<<st<<'\n'; while (st+1<lx&&pw[st+1]<=cur) st++; for (int i=kx-1; i>=0; i--) if (dp[st][x][i].t>cur) cur+=dp[st][x][i].cost, x=dp[st][x][i].out; //cout<<"here "<<i<<' '<<cur<<' '<<x<<'\n'; //cout<<"after "<<x<<' '<<cur<<' '<<st<<'\n'; if (cur>=S[x]) cur+=S[x], x=W[x]; else cur+=P[x], x=L[x]; } return cur+dist[x]; }
#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...