Submission #609315

#TimeUsernameProblemLanguageResultExecution timeMemory
609315lorenzoferrariDungeons Game (IOI21_dungeons)C++17
50 / 100
7033 ms490656 KiB
#include "dungeons.h" #include <bits/stdc++.h> #pragma GCC optimize ("O3") using namespace std; using vi = vector<int>; using LL = long long; constexpr int LG = 25; struct nd { int v; // final node LL inc; // total str increase LL ini; // min/max str needed so far }; nd wjoin(nd a, nd b) { nd ans; ans.v = b.v; ans.inc = a.inc + b.inc; ans.ini = max(a.ini, b.ini - a.inc); return ans; } nd ljoin(nd a, nd b) { nd ans; ans.v = b.v; ans.inc = a.inc + b.inc; ans.ini = min(a.ini, b.ini - a.inc); return ans; } int n; vi s, p, w, l; vector<array<nd, LG>> wlift; vector<array<nd, LG>> llift; void init(int n, vi s, vi p, vi w, vi l) { ::n = n; s.push_back(0); p.push_back(0); w.push_back(n); l.push_back(n); ::s = s, ::p = p, ::w = w, ::l = l; wlift.resize(n+1); llift.resize(n+1); for (int i = 0; i < n; ++i) { wlift[i][0].v = w[i]; llift[i][0].v = l[i]; wlift[i][0].inc = s[i]; llift[i][0].inc = p[i]; wlift[i][0].ini = s[i]; llift[i][0].ini = s[i] - 1; } wlift[n][0] = {n, 0, 0}; llift[n][0] = {n, 0, 0}; for (int i = 1; i < LG; ++i) { for (int j = 0; j <= n; ++j) { int wm = wlift[j][i-1].v; int lm = llift[j][i-1].v; wlift[j][i] = wjoin(wlift[j][i-1], wlift[wm][i-1]); llift[j][i] = ljoin(llift[j][i-1], llift[lm][i-1]); } } } void keep_winning(int& x, LL& z) { for (int i = LG-1; i >= 0; --i) { if (z >= wlift[x][i].ini) { z += wlift[x][i].inc; x = wlift[x][i].v; } } } void keep_losing(int& x, LL& z) { for (int i = LG-1; i >= 0; --i) { if (z <= llift[x][i].ini) { z += llift[x][i].inc; x = llift[x][i].v; } } } LL simulate(int x, int zi) { LL z = zi; int i = x; while (i != n) { keep_winning(i, z); keep_losing(i, z); } return z; }
#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...