# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
439680 | tutis | Dungeons Game (IOI21_dungeons) | C++17 | 0 ms | 0 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 "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
long long N;
long long mn[400002][19];
long long W[400002][19];
long long S[400002][19];
long long P[400002][19];
long long mx[400002][19];
long long L[400002][19];
long long mn1[23][400002][19];
long long mx1[23][400002][19];
long long tp[23][400002][19];
long long del[23][400002][19];
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
N = n;
for (int i = 0; i < s.size(); i++)
{
S[i][0] = s[i];
mx[i][0] = s[i] - 1;
mn[i][0] = s[i];
}
for (int i = 0; i < p.size(); i++)
P[i][0] = p[i];
for (int i = 0; i < w.size(); i++)
W[i][0] = w[i];
for (int i = 0; i < l.size(); i++)
L[i][0] = l[i];
mx[n][0] = 1e17;
L[n][0] = n;
P[n][0] = 0;
mn[n][0] = -1e17;
S[n][0] = 0;
W[n][0] = n;
for (int t = 1; t < 19; t++)
{
for (int i = 0; i <= n; i++)
{
mx[i][t] = min(mx[i][t - 1], mx[L[i][t - 1]][t - 1] - P[i][t - 1]);
L[i][t] = L[L[i][t - 1]][t - 1];
P[i][t] = P[i][t - 1] + P[L[i][t - 1]][t - 1];
}
}
for (int t = 1; t < 19; t++)
{
for (int i = 0; i <= n; i++)
{
mn[i][t] = max(mn[i][t - 1], mn[W[i][t - 1]][t - 1] - S[i][t - 1]);
W[i][t] = W[W[i][t - 1]][t - 1];
S[i][t] = S[i][t - 1] + S[W[i][t - 1]][t - 1];
}
}
}
long long simulate(int x, int z) {
long long s = z;
while (x != N)
{
if (s >= mn[x][0])
{
for (int t = 18; t >= 0; t--)
{
if (s >= mn[x][t])
{
s += S[x][t];
x = W[x][t];
}
if (s < mn[x][0])
break;
}
}
else
{
for (int t = 18; t >= 0; t--)
{
if (s <= mx[x][t])
{
s += P[x][t];
x = L[x][t];
}
if (s >= mn[x][0])
break;
}
}
}
return s;
}