#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define sig signed
#define int long long
#define vec vector
#define arr array
const int N = 5e4 + 5, LG = 27, INF = 1e18;
int n;
arr<int, N> wn, ls, wn_nd, ls_nd;
arr<arr<arr<vec<int>, N>, LG>, LG> jmp;
void jmp_cmp() {
for (int i = 0; i <= 25; i++) {
for (int u = 0; u <= n; u++) {
if ((1 << i) >= wn[u])
jmp[i][0][u] = {wn_nd[u], wn[u], (1 << (i + 1)) - 1};
// jmp[i][0][u] = {wn_nd[u], wn[u], (1 << (i + 1)) - 1};
else
jmp[i][0][u] = {ls_nd[u], ls[u], wn[u] - 1};
}
for (int j = 1; j <= 25; j++) {
for (int u = 0; u <= n; u++) {
vec<int> x = jmp[i][j - 1][u];
vec<int> y = jmp[i][j - 1][x[0]];
jmp[i][j][u] = {y[0], x[1] + y[1], min(x[2], y[2] - x[1])};
}
}
}
// cout << jmp[0][1][0][0] << " " << jmp[0][1][0][1] << '\n';
}
void init(sig _n, vec<sig> _wn, vec<sig> _ls, vec<sig> _wn_nd, vec<sig> _ls_nd) {
n = _n;
for (int u = 0; u < n; u++)
wn[u] = _wn[u], ls[u] = _ls[u], wn_nd[u] = _wn_nd[u], ls_nd[u] = _ls_nd[u];
wn[n] = ls[n] = 0, wn_nd[n] = ls_nd[n] = n;
jmp_cmp();
}
int fnd(int x) {
for (int i = 25; i >= 0; i--)
if (x >= (1 << i)) return i;
assert(false); return -1;
}
void mv(int &u, int &s) {
if (u == n) return;
if (s >= wn[u]) {
s += wn[u];
u = wn_nd[u];
} else {
s += ls[u];
u = ls_nd[u];
}
}
int simulate(sig _u, sig _s) {
int u = _u, s = _s;
while (u != n) {
int i = fnd(s);
for (int j = 25; j >= 0; j--) {
vec<int> &x = jmp[i][j][u];
if (s > x[2]) continue;
if (x[0] == n) continue;
// cout << i << " " << j << " " << u << ": " << x[0] << " " << x[1] << '\n';
u = x[0], s += x[1];
}
mv(u, s);
}
return s;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |