Submission #1050899

#TimeUsernameProblemLanguageResultExecution timeMemory
1050899BlagojDungeons Game (IOI21_dungeons)C++17
100 / 100
4304 ms1792936 KiB
#include <bits/stdc++.h> #include "dungeons.h" #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("Ofast,unroll-loops") using namespace std; #define ll long long #define inf 1e17 const int mxn = 4e5 + 10, LOG1 = 25, LOG2 = 9, BASE = 8; // steps, pwr int n; vector<int> s, p, w, l; int go[mxn][LOG1][LOG2]; ll gain[mxn][LOG1][LOG2], lim[mxn][LOG1][LOG2]; ll F[LOG2]; void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) { F[0] = 1; for (int i = 1; i < LOG2; i++) F[i] = F[i - 1] * BASE; n = _n, s = _s, p = _p, w = _w, l = _l; for (int pwr = 0; pwr < LOG2; pwr++) { for (int i = 0; i < n; i++) { if (F[pwr] >= s[i]) { if (w[i] == n) go[i][0][pwr] = -1; else { go[i][0][pwr] = w[i]; gain[i][0][pwr] = s[i]; lim[i][0][pwr] = inf; } } else { if (l[i] == n) go[i][0][pwr] = -1; else { go[i][0][pwr] = l[i]; gain[i][0][pwr] = p[i]; lim[i][0][pwr] = s[i]; } } } } for (int pwr = 0; pwr < LOG2; pwr++) { for (int steps = 1; steps < LOG1; steps++) { for (int i = 0; i < n; i++) { int nxt = go[i][steps - 1][pwr]; if (go[i][steps - 1][pwr] == -1 || go[nxt][steps - 1][pwr] == -1) go[i][steps][pwr] = -1; else { go[i][steps][pwr] = go[nxt][steps - 1][pwr]; gain[i][steps][pwr] = gain[i][steps - 1][pwr] + gain[nxt][steps - 1][pwr]; lim[i][steps][pwr] = min(lim[i][steps - 1][pwr], lim[nxt][steps - 1][pwr] - gain[i][steps - 1][pwr]); } } } } } ll simulate(int x, int z) { ll ans = z; int pwr = 0; while (x != n) { while (pwr + 1 < LOG2 && F[pwr + 1] <= ans) pwr++; for (int i = LOG1 - 1; i >= 0; i--) { if (go[x][i][pwr] == -1) continue; if (ans >= lim[x][i][pwr]) continue; ans += gain[x][i][pwr]; x = go[x][i][pwr]; } if (ans >= s[x]) { ans += s[x]; x = w[x]; } else { ans += p[x]; x = l[x]; } } return ans; }
#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...