Submission #924855

#TimeUsernameProblemLanguageResultExecution timeMemory
924855Programmer123Dungeons Game (IOI21_dungeons)C++17
11 / 100
7082 ms1374436 KiB
#include "dungeons.h" #include <bits/stdc++.h> std::vector<int> s, p, w, l; int N; long long *minBlitz, *gainBlitz; long long dp(int node, long long str); long long calc(int node, long long str) { if (str >= s[node]) { return dp(w[node], str + s[node]); } else return dp(l[node], str + p[node]); } std::unordered_map<long long, long long> *cache; long long dp(int node, long long str) { assert(node != N); if (str >= minBlitz[node]) return str + gainBlitz[node]; if (!cache[node].count(str)) { cache[node][str] = calc(node, str); } return cache[node][str]; } void init(int n, std::vector<int> _s, std::vector<int> _p, std::vector<int> _w, std::vector<int> _l) { N = n; s = std::move(_s); p = std::move(_p); w = std::move(_w); l = std::move(_l); minBlitz = new long long[N + 1]; gainBlitz = new long long[N + 1]; for (int i = 0; i <= N; ++i) { gainBlitz[i] = -1; } std::function<void(int)> calc = [&](int x) { if (gainBlitz[x] != -1) return; if (x == N) { minBlitz[x] = 0; gainBlitz[x] = 0; return; } calc(w[x]); minBlitz[x] = std::max(minBlitz[w[x]] - s[x], (long long) s[x]); gainBlitz[x] = gainBlitz[w[x]] + s[x]; }; for (int i = 0; i <= N; ++i) { calc(i); } cache = new std::remove_pointer<decltype(cache)>::type[N + 1]; #ifdef LOCAL std::cout << "minBlitz:"; for (int i = 0; i <= N; ++i) { std::cout << " " << minBlitz[i]; } std::cout << std::endl; std::cout << "gainBlitz:"; for (int i = 0; i <= N; ++i) { std::cout << " " << gainBlitz[i]; } std::cout << std::endl; #endif } long long simulate(int x, int z) { return dp(x, 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...