제출 #442526

#제출 시각아이디문제언어결과실행 시간메모리
442526JovanB던전 (IOI21_dungeons)C++17
100 / 100
6142 ms1711568 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 400000; const int LOG2 = 23; const int LOG8 = 8; const ll INF = 1000000000000000000LL; ll dp[LOG8+1][MAXN+5][LOG2+1]; ll dod[LOG8+1][MAXN+5][LOG2+1]; int gde[LOG8+1][MAXN+5][LOG2+1]; int s[MAXN+5]; int pl[MAXN+5]; int win[MAXN+5]; int lose[MAXN+5]; int step8[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; step8[0] = 1; for(int i=1; i<=LOG8; i++) step8[i] = 8*step8[i-1]; for(int k=0; k<=LOG8; k++){ for(int i=0; i<=n; i++){ if(step8[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]; ll mndp = dp[k][i][j-1]; ll udod = dod[k][i][j-1]; for(int times=1; times<2; times++){ mndp = min(mndp, dp[k][h][j-1] - 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, -5LL); } } } return; } ll simuliraj(int x, ll z){ if(x == N) return z; int k = 0; for(int j=0; j<=LOG8; j++){ if(step8[j] <= z) k = j; } if(k == LOG8) return z + dod[k][x][20]; 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...