Submission #1019390

#TimeUsernameProblemLanguageResultExecution timeMemory
1019390aykhnDungeons Game (IOI21_dungeons)C++17
11 / 100
718 ms1210280 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; #define inf 0x3F3F3F3F3F3F3F3F const int MXN = 5e4 + 5; const int LOG = 24; int N; vector<long long> p[LOG][LOG], mn[LOG][LOG], gain[LOG][LOG]; struct Tree { int id; void givesz() { for (int i = 0; i < LOG; 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 < LOG; lg++) { for (int i = 0; i <= N; i++) { mn[id][lg][i] = min(mn[id][lg - 1][i], mn[id][lg - 1][p[id][lg - 1][i]] - gain[id][lg - 1][i]); gain[id][lg][i] = gain[id][lg - 1][i] + gain[id][lg - 1][p[id][lg - 1][i]]; p[id][lg][i] = p[id][lg - 1][p[id][lg - 1][i]]; } } } void move(int &x, long long &val) { if (x == N) return; for (int i = LOG - 1; i >= 0; i--) { if (val < mn[id][i][x]) { val += gain[id][i][x]; x = p[id][i][x]; } } } }; 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; 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...