제출 #712622

#제출 시각아이디문제언어결과실행 시간메모리
712622danikoynovDungeons Game (IOI21_dungeons)C++17
0 / 100
7081 ms39952 KiB
#include "dungeons.h" #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 4e5 + 10, maxlog = 20; int n, w[maxn], l[maxn]; ll s[maxn], p[maxn]; vector < int > child[maxn]; struct jump { ll sum, max_strenght; int ver; }; jump dp[maxlog][maxn]; void dfs(int v) { dp[0][v].ver = w[v]; dp[0][v].sum = s[v]; dp[0][v].max_strenght = s[v]; for (int j = 1; j < maxlog; j ++) { dp[j][v].sum = dp[j - 1][v].sum + dp[j - 1][dp[j - 1][v].ver].sum; dp[j][v].ver = dp[j - 1][dp[j - 1][v].ver].ver; dp[j][v].max_strenght = max(dp[j - 1][v].max_strenght, dp[j - 1][dp[j - 1][v].ver].max_strenght); } for (int u : child[v]) { dfs(u); } } 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]; p[i] = P[i]; w[i] = W[i]; l[i] = L[i]; child[w[i]].push_back(i); } for (int j = 0; j < maxlog; j ++) dp[j][n].ver = n; w[n] = n; dfs(n); return; } long long simulate(int x, int z) { ll strength = z; while(x != n) { if (strength >= s[x]) { for (int bit = maxlog - 1; bit > 0; bit --) { if (dp[bit][x].max_strenght < strength + s[x]) { strength += dp[bit][x].sum; x = dp[bit][x].ver; } } strength += s[x]; x = w[x]; } else { strength += p[x]; x = l[x]; } } return strength; }
#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...