Submission #442519

#TimeUsernameProblemLanguageResultExecution timeMemory
442519JovanBDungeons Game (IOI21_dungeons)C++17
89 / 100
7227 ms1585832 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 400000; const int LOG2 = 24; const int LOG6 = 9; const int INF = 1000000000; int dp[LOG6+1][MAXN+5][LOG2+1]; ll dod[LOG6+1][MAXN+5][LOG2+1]; int gde[LOG6+1][MAXN+5][LOG2+1]; int s[MAXN+5]; int pl[MAXN+5]; int win[MAXN+5]; int lose[MAXN+5]; int step6[MAXN+5]; int N; void init(int n, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L){ N = n; for(int i=0; i<n; i++){ s[i] = S[i]; pl[i] = P[i]; win[i] = W[i]; lose[i] = L[i]; } s[n] = 0; pl[n] = 0; win[n] = n; lose[n] = n; step6[0] = 1; for(int i=1; i<=LOG6; i++) step6[i] = 6*step6[i-1]; for(int k=0; k<=LOG6; k++){ for(int i=0; i<=n; i++){ if(step6[k] >= s[i]){ dp[k][i][0] = INF; dod[k][i][0] = s[i]; gde[k][i][0] = win[i]; } else{ dp[k][i][0] = s[i] - 1; dod[k][i][0] = pl[i]; gde[k][i][0] = lose[i]; } } for(int j=1; j<=LOG2; j++){ for(int i=0; i<=n; i++){ int h = gde[k][i][j-1]; int mndp = dp[k][i][j-1]; ll udod = dod[k][i][j-1]; for(int times=1; times<2; times++){ mndp = min(1LL*mndp, dp[k][h][j-1] == INF ? INF : dp[k][h][j-1] - min(1LL*INF, udod)); udod += dod[k][h][j-1]; h = gde[k][h][j-1]; } gde[k][i][j] = h; dod[k][i][j] = udod; dp[k][i][j] = max(mndp, -5); } } } return; } ll simuliraj(int x, ll z){ if(x == N) return z; int k = 0; for(int j=0; j<=LOG6; j++){ if(step6[j] <= z) k = j; } for(int j=LOG2; j>=0; j--){ for(int times=0; times<2; times++){ if(dp[k][x][j] >= z){ z += dod[k][x][j]; x = gde[k][x][j]; } else break; } } if(x == N) return z; if(z >= s[x]) return simuliraj(win[x], z + s[x]); return simuliraj(lose[x], z + pl[x]); } long long simulate(int x, int z) { return simuliraj(x, 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...