Submission #442504

#TimeUsernameProblemLanguageResultExecution timeMemory
442504JovanBDungeons Game (IOI21_dungeons)C++17
63 / 100
6358 ms972044 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 50000; const int LOG2 = 24; const int LOG4 = 11; const int INF = 1000000000; int dp[LOG2+1][MAXN+5][LOG2+1]; ll dod[LOG2+5][MAXN+5][LOG2+1]; int gde[LOG2+5][MAXN+5][LOG2+1]; int s[MAXN+5]; int pl[MAXN+5]; int win[MAXN+5]; int lose[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; for(int k=0; k<=LOG2; k++){ for(int i=0; i<=n; i++){ if((1<<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++){ gde[k][i][j] = gde[k][gde[k][i][j-1]][j-1]; dod[k][i][j] = dod[k][i][j-1] + dod[k][gde[k][i][j-1]][j-1]; dp[k][i][j] = min(1LL*dp[k][i][j-1], (dp[k][gde[k][i][j-1]][j-1] == INF ? INF : dp[k][gde[k][i][j-1]][j-1] - min(1LL*INF, dod[k][i][j-1]))); dp[k][i][j] = max(dp[k][i][j], -5); } } } return; } ll simuliraj(int x, ll z){ if(x == N) return z; int k = 0; for(int j=0; j<=LOG2; j++){ if((1<<j) <= z) k = j; } for(int j=LOG2; j>=0; j--){ if(dp[k][x][j] >= z){ z += dod[k][x][j]; x = gde[k][x][j]; } } 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...