Submission #525493

#TimeUsernameProblemLanguageResultExecution timeMemory
525493LucaDantasDungeons Game (IOI21_dungeons)C++17
63 / 100
3936 ms2083932 KiB
#include "dungeons.h" #include <vector> constexpr int maxn = 4e5+10, logn = 24, log_lift = 11, base_lift = 4; constexpr int inf = 0x3f3f3f3f, maxv = 1e7+10; struct FunctionalGraph { int f[maxn][log_lift], mn[maxn][log_lift]; int tab[maxn][log_lift]; long long cost[maxn][log_lift]; void add_i(const int& i, const int& x, const int& v, const int& st) { f[i][0] = x, cost[i][0] = v, mn[i][0] = i, tab[i][0] = st; } void build(int n) { f[n][0] = n; mn[n][0] = n; for(int l = 1; l < log_lift; l++) { for(int i = 0; i <= n; i++) { f[i][l] = i; tab[i][l] = tab[i][l-1]; mn[i][l] = mn[i][l-1]; for(int k = 0; k < base_lift; k++) { if(tab[i][l] > tab[f[i][l]][l-1] - cost[i][l]) { mn[i][l] = mn[f[i][l]][l-1]; if(tab[f[i][l]][l-1] < maxv) tab[i][l] = std::max(0ll, tab[f[i][l]][l-1] - cost[i][l]); } cost[i][l] += cost[f[i][l]][l-1]; f[i][l] = f[f[i][l]][l-1]; } } } } void go(int& x, long long& val) { for(int l = log_lift-1; l >= 0; l--) for(int k = 0; k < base_lift-1; k++) if(tab[x][l] > val || tab[x][l] >= maxv) val += cost[x][l], x = f[x][l]; } } graph[logn]; int N; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { N = n; for(int lg = 0; lg < logn; lg++) { for(int i = 0; i < n; i++) { if(s[i] < (2<<lg)) graph[lg].add_i(i, w[i], s[i], inf); else graph[lg].add_i(i, l[i], p[i], s[i]); } graph[lg].build(n); } return; } long long simulate(int x, int z) { if(N > (int)1e5) return 0; long long val = z; for(int lg = 0; lg < logn; lg++) if(x != N) graph[lg].go(x, val); return val; }
#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...