# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
794693 | finn__ | Dungeons Game (IOI21_dungeons) | C++17 | 7151 ms | 1423224 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "dungeons.h"
using namespace std;
constexpr size_t N = 400001, K = 25, L = 9;
size_t n;
uint32_t f[L][N][K], m[L][N][K];
uint64_t u[L][N][K];
vector<int> s, p, w, l;
void init(int n_, vector<int> s_, vector<int> p_, vector<int> w_, vector<int> l_)
{
n = n_;
s = move(s_);
p = move(p_);
w = move(w_);
l = move(l_);
for (size_t k = 0; k < L; ++k)
{
for (size_t i = 0; i < n; ++i)
{
if (s[i] < 1ULL << (k * 3))
f[k][i][0] = w[i], u[k][i][0] = s[i], m[k][i][0] = UINT32_MAX;
else
f[k][i][0] = l[i], u[k][i][0] = p[i], m[k][i][0] = s[i];
}
f[k][n][0] = n;
u[k][n][0] = 0;
m[k][n][0] = UINT32_MAX;
for (size_t j = 1; j < K; ++j)
for (size_t i = 0; i < n; ++i)
{
size_t const intermediate = f[k][i][j - 1];
f[k][i][j] = f[k][intermediate][j - 1];
u[k][i][j] = u[k][i][j - 1] + u[k][intermediate][j - 1];
m[k][i][j] = m[k][i][j - 1];
if (m[k][intermediate][j - 1] != UINT32_MAX)
{
uint32_t v = m[k][intermediate][j - 1] - min<uint64_t>(m[k][intermediate][j - 1],
u[k][i][j - 1]);
m[k][i][j] = min(m[k][i][j], v);
}
}
}
}
long long simulate(int x, int z)
{
long long strength = z;
while (x != n)
{
if (strength >= s[x])
{
strength += s[x];
x = w[x];
}
else
{
strength += p[x];
x = l[x];
}
size_t const k = min<size_t>(L - 1, __lg(strength) / 3);
#pragma GCC unroll K
for (size_t j = K - 1; j < K; --j)
if (m[k][x][j] > strength)
{
strength += u[k][x][j];
x = f[k][x][j];
break;
}
}
return strength;
}
Compilation message (stderr)
# | 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... |