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;
const int mxt = 7;
long long f(int x)
{
long long r = 1;
long long w = 1;
while (x--)
{
w *= 8;
r *= w;
}
return r;
}
const int mxp = 18;
int mn1[mxt][400002][mxp];
int mx1[mxt][400002][mxp];
int tp[mxt][400002][mxp];
int del[mxt][400002][mxp];
long long mn[400002];
long long delt[400002];
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
N = n;
mn[n] = -1e17;
delt[n] = 0;
for (int i = n - 1; i >= 0; i--)
{
mn[i] = max((long long)s[i], mn[w[i]] - s[i]);
delt[i] = s[i] + delt[w[i]];
}
for (int x = 0; x < mxt; x++)
{
long long v = f(x);
mn1[x][n][0] = -3e7;
mx1[x][n][0] = 3e7;
tp[x][n][0] = n;
del[x][n][0] = 0;
for (int i = 0; i < n; i++)
{
if (s[i] > v)
{
mn1[x][i][0] = -1e8;
mx1[x][i][0] = s[i] - 1;
tp[x][i][0] = l[i];
del[x][i][0] = p[i];
}
else
{
mn1[x][i][0] = s[i];
mx1[x][i][0] = 1e8;
tp[x][i][0] = w[i];
del[x][i][0] = s[i];
}
}
for (int t = 1; t < mxp; t++)
{
for (int i = 0; i <= n; i++)
{
int i_ = tp[x][i][t - 1];
int del_ = del[x][i][t - 1];
mn1[x][i][t] = max(mn1[x][i][t - 1], mn1[x][i_][t - 1] - del_);
mx1[x][i][t] = min(mx1[x][i][t - 1], mx1[x][i_][t - 1] - del_);
tp[x][i][t] = tp[x][i_][t - 1];
del[x][i][t] = del[x][i][t - 1] + del[x][i_][t - 1];
if (del[x][i][t] >= 2e8)
{
mn1[x][i][t] = mn1[x][i][t - 1];
mx1[x][i][t] = mx1[x][i][t - 1];
tp[x][i][t] = tp[x][i][t - 1];
del[x][i][t] = del[x][i][t - 1];
}
}
}
}
}
long long simulate(int x, int z) {
long long s = z;
while (s < mn[x])
{
for (int v = mxt - 1; v >= 0; v--)
{
if (s >= mn1[v][x][0] && s <= mx1[v][x][0])
for (int t = mxp - 1; t >= 0; t--)
{
if (s >= mn1[v][x][t] && s <= mx1[v][x][t])
{
s += del[v][x][t];
x = tp[v][x][t];
}
}
}
}
return s + delt[x];
}
# | 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... |