Submission #618910

#TimeUsernameProblemLanguageResultExecution timeMemory
618910SlavicGDungeons Game (IOI21_dungeons)C++17
0 / 100
1 ms1152 KiB
#include "dungeons.h" #include "bits/stdc++.h" using namespace std; using ll = long long; const int N = 4e5 + 10, K = 30; ll jump[N][K], jump2[N][K], finish; ll sum[N][K], S[N], P[N], W[N], L[N]; void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { finish = n; jump[n][0] = n; for(int i = 0; i < n; ++i) { S[i] = s[i]; P[i] = p[i]; W[i] = w[i]; L[i] = l[i]; jump[i][0] = l[i]; sum[i][0] = p[i]; jump2[i][0] = w[i]; } for(int j = 1; j < K; ++j) { for(int i = 0; i <= n; ++i) { jump[i][j] = jump[jump[i][j - 1]][j - 1]; jump2[i][j] = jump2[jump2[i][j - 1]][j - 1]; sum[i][j] = sum[i][j - 1] + sum[jump[i][j - 1]][j - 1]; } } } long long simulate(int x, int z) { ll w = z; for(ll j = K - 1; j >= 0; --j) { if(w + sum[x][j] < S[0] && jump[x][j] != finish) { w += sum[x][j]; x = jump[x][j]; } } if(w < S[0]) { w += sum[x][0]; x = jump[x][0]; } ll steps = 0; for(ll j = K - 1; j >= 0; --j) { if(jump2[x][j] != finish) { steps += (1LL << j); x = jump2[x][j]; } } if(x != finish) ++steps; w += 1LL * steps * S[0]; return w; }
#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...