Submission #819273

#TimeUsernameProblemLanguageResultExecution timeMemory
819273LittleCubeDungeons Game (IOI21_dungeons)C++17
100 / 100
4337 ms1988472 KiB
#include "dungeons.h" #include <bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define F first #define S second using namespace std; namespace { struct node { // value, >= m wil accidently big win (just like mango) ll v, m; }; node merge(node l, node r) { auto [lv, lm] = l; auto [rv, rm] = r; return node{lv + rv, min(lm, rm - lv)}; } const int C = 10'000'000, P = 25, B = 6, mxL = 10; pair<int, vector<int>> calc() { vector<int> v; int b = 1; for (; b < C; b *= B) v.emplace_back(b); v.emplace_back(b); return make_pair(v.size(), v); } int n, m, L; int id[mxL][400001][P]; node go[mxL][400001][P]; vector<int> s, p, w, l, base; } void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { ::n = n; ::s = s, ::p = p, ::w = w, ::l = l; tie(L, base) = calc(); cerr << L << '\n'; for (int t = 0; t < L; t++) { for (int i = 0; i < n; i++) if (s[i] <= base[t]) go[t][i][0] = node{s[i], (ll)1e18}, id[t][i][0] = w[i]; else go[t][i][0] = node{p[i], s[i]}, id[t][i][0] = l[i]; go[t][n][0] = node{0, 0}, id[t][n][0] = n; for (int k = 0; k + 1 < P; k++) for (int i = 0; i <= n; i++) go[t][i][k + 1] = merge(go[t][i][k], go[t][id[t][i][k]][k]), id[t][i][k + 1] = id[t][id[t][i][k]][k]; } return; } ll simulate(int x, int _z) { ll z = _z; int c = upper_bound(base.begin(), base.end(), _z) - base.begin() - 1; for (int k = P - 1; k >= 0; k--) if (go[c][x][k].m > z) z += go[c][x][k].v, x = id[c][x][k]; if (x == n) return z; z += s[x]; x = w[x]; return simulate(x, z); }

Compilation message (stderr)

dungeons.cpp:36:9: warning: '{anonymous}::m' defined but not used [-Wunused-variable]
   36 |  int n, m, L;
      |         ^
#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...