Submission #1019402

#TimeUsernameProblemLanguageResultExecution timeMemory
1019402aykhnDungeons Game (IOI21_dungeons)C++17
89 / 100
7098 ms1918540 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F const int MXN = 5e4 + 5; const int LOG = 25; const int LG = 8; int N; vector<long long> p[LOG][LG], mn[LOG][LG], gain[LOG][LG]; struct Tree { int id; void givesz() { for (int i = 0; i < LG; i++) p[id][i].assign(N + 1, 0), mn[id][i].assign(N + 1, 0), gain[id][i].assign(N + 1, 0); } void init() { for (int lg = 1; lg < LG; lg++) { for (int i = 0; i <= N; i++) { mn[id][lg][i] = mn[id][lg - 1][i]; gain[id][lg][i] = gain[id][lg - 1][i]; p[id][lg][i] = p[id][lg - 1][i]; for (int j = 1; j < LG; j++) { mn[id][lg][i] = min(mn[id][lg][i], mn[id][lg - 1][p[id][lg][i]] - gain[id][lg][i]); gain[id][lg][i] = gain[id][lg][i] + gain[id][lg - 1][p[id][lg][i]]; p[id][lg][i] = p[id][lg - 1][p[id][lg][i]]; } } } } void move(int &x, long long &val) { if (x == N) return; for (int i = LG - 1; i >= 0; i--) { for (int j = 0; j < LG; j++) { if (val < mn[id][i][x]) { val += gain[id][i][x]; x = p[id][i][x]; } else break; } } } }; Tree t[LOG]; vector<long long> S, P, W, L; void init(int n, vector<int> s1, vector<int> p1, vector<int> w1, vector<int> l1) { N = n; for (int &i : s1) S.push_back(i); for (int &i : p1) P.push_back(i); for (int &i : w1) W.push_back(i); for (int &i : l1) L.push_back(i); for (int i = 0; i < LOG; i++) { t[i].id = i; t[i].givesz(); for (int j = 0; j < N; j++) { if (s1[j] < (1LL << i)) { p[i][0][j] = w1[j]; gain[i][0][j] = s1[j]; mn[i][0][j] = inf; } else { p[i][0][j] = l1[j]; gain[i][0][j] = p1[j]; mn[i][0][j] = s1[j]; } } p[i][0][N] = N, gain[i][0][N] = 0, mn[i][0][N] = -inf; t[i].init(); } } long long simulate(int x, int z) { long long val = z; while (x != N) { int lg = 0; long long tmp = val; while (tmp > 1) lg++, tmp >>= 1; lg = min(lg, LOG - 1); t[lg].move(x, val); if (x == N) break; val += S[x]; x = W[x]; } 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...