Submission #438429

#TimeUsernameProblemLanguageResultExecution timeMemory
438429mango_lassiDungeons Game (IOI21_dungeons)C++17
89 / 100
7073 ms632520 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 4 * (int)1e5; const int C = 3; const int H = 24 / C; const ll INF = 1e9 + 7; pair<int, pair<ll, ll>> jmp[N + 1][H][H]; ll add[N + 1]; ll str[N + 1]; ll bns[N + 1]; int wt[N + 1]; int lt[N + 1]; int n; pair<int, ll> advance(pair<int, ll> cur) { if (str[cur.first] > cur.second) return {lt[cur.first], bns[cur.first] + cur.second}; else return {wt[cur.first], str[cur.first] + cur.second}; } void init(int n_, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { n = n_; for (int i = 0; i < n; ++i) str[i] = s[i]; for (int i = 0; i < n; ++i) bns[i] = p[i]; for (int i = 0; i < n; ++i) wt[i] = w[i]; for (int i = 0; i < n; ++i) lt[i] = l[i]; str[n] = INF; bns[n] = INF; wt[n] = n; lt[n] = n; add[n] = 0; for (int i = n-1; i >= 0; --i) add[i] = add[wt[i]] + str[i]; for (int a = 0; a < H; ++a) { ll lo = 1 << (C * a); ll hi = 1 << (C * (a + 1)); for (int i = 0; i <= n; ++i) { if ((lo < str[i] && str[i] < hi) || i == n) { jmp[i][a][0] = {lt[i], {str[i], bns[i]}}; } else if (str[i] <= lo) { jmp[i][a][0] = {wt[i], {INF, str[i]}}; } else { jmp[i][a][0] = {lt[i], {INF, bns[i]}}; } } for (int b = 1; b < H; ++b) { for (int i = 0; i <= n; ++i) { int j = i; ll min_str = INF, str_add = 0; for (int it = 1; it < (1 << C); ++it) { auto pr = jmp[j][a][b - 1]; min_str = min(min_str, pr.second.first - str_add); str_add += pr.second.second; j = pr.first; } jmp[i][a][b] = {j, {min_str, str_add}}; } } } } long long simulate(int start_i, int ini_pwr) { pair<int, ll> state = {start_i, (ll)ini_pwr}; for (int a = 0; a < H; ++a) { ll lo = 1 << (C * a); ll hi = 1 << (C * (a + 1)); while(state.first != n && lo <= state.second && state.second < hi) { for (int b = H-1; b >= 0; --b) { while(state.second < jmp[state.first][a][b].second.first && state.second + jmp[state.first][a][b].second.second < hi) { state.second += jmp[state.first][a][b].second.second; state.first = jmp[state.first][a][b].first; } } if (state.first != n) state = advance(state); // either win against opponent in same strength bracket, or break out of strength bracket } } return state.second + add[state.first]; }
#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...