# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
794657 | finn__ | Dungeons Game (IOI21_dungeons) | C++17 | 7174 ms | 1479520 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 = 26, L = 9;
size_t n;
uint32_t f[L][K][N], m[L][K][N];
uint64_t u[L][K][N];
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][0][i] = w[i], u[k][0][i] = s[i], m[k][0][i] = UINT32_MAX;
else
f[k][0][i] = l[i], u[k][0][i] = p[i], m[k][0][i] = s[i];
}
f[k][0][n] = n;
u[k][0][n] = 0;
m[k][0][n] = UINT32_MAX;
for (size_t j = 1; j < K; ++j)
for (size_t i = 0; i < n; ++i)
{
size_t const intermediate = f[k][j - 1][i];
f[k][j][i] = f[k][j - 1][intermediate];
u[k][j][i] = u[k][j - 1][i] + u[k][j - 1][intermediate];
if (intermediate == n)
m[k][j][i] = UINT32_MAX;
m[k][j][i] = m[k][j - 1][i];
if (m[k][j - 1][intermediate] != UINT32_MAX)
m[k][j][i] = min<uint64_t>(m[k][j][i],
min<uint64_t>(m[k][j - 1][i],
m[k][j - 1][intermediate] -
min<uint64_t>(m[k][j - 1][intermediate],
u[k][j - 1][i])));
}
}
}
long long simulate(int x, int z)
{
long long strength = z;
while (x != n)
{
size_t const k = min<size_t>(L - 1, __lg(strength) / 3);
for (size_t j = K - 1; j < K; --j)
if (m[k][j][x] > strength)
{
strength += u[k][j][x];
x = f[k][j][x];
break;
}
if (x != n)
{
if (strength >= s[x])
{
strength += s[x];
x = w[x];
}
else
{
strength += p[x];
x = l[x];
}
}
}
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... |