제출 #794140

#제출 시각아이디문제언어결과실행 시간메모리
794140Johann던전 (IOI21_dungeons)C++17
0 / 100
74 ms51644 KiB
#include "dungeons.h" #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<pii> vpii; typedef vector<vpii> vvpii; #define sz(x) (int)(x).size() int N; const ll INF = 1LL << 60; vi S, P; vector<int> W, L; vi dpWin; vvpii dpLos; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { N = n; S.resize(N), P.resize(N); W = w, L = l; for (int i = 0; i < N; ++i) S[i] = s[i], P[i] = p[i]; dpWin.assign(N + 1, INF); dpWin[N] = 0; for (int i = N - 1; i >= 0; --i) dpWin[i] = S[i] + dpWin[W[i]]; dpLos.assign(N, vpii(ceil(log2(S[0]) + 1))); for (int i = 0; i < N; ++i) dpLos[i][0] = {L[i], P[i]}; for (int j = 1; j < sz(dpLos.back()); ++j) for (int i = 0; i < N; ++i) dpLos[i][j] = {dpLos[dpLos[i][j - 1].first][j - 1].first, dpLos[dpLos[i][j - 1].first][j - 1].second + dpLos[i][j - 1].second}; return; } long long simulate(int x, int z) { ll ans = z; for (int j = sz(dpLos.back()) - 1; j >= 0; --j) { if (dpLos[x][j].second + ans < S[x]) { ans += dpLos[x][j].second; x = dpLos[x][j].first; } } if (ans < S[x]) { ans += dpLos[x][0].second; x = dpLos[x][0].first; } return ans + dpWin[x]; }
#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...