이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e5 + 10, maxlog = 20;
int n, w[maxn], l[maxn];
ll s[maxn], p[maxn];
vector < int > child[maxn];
struct jump
{
ll sum, max_strenght;
int ver;
};
jump dp[maxlog][maxn];
void dfs(int v)
{
dp[0][v].ver = w[v];
dp[0][v].sum = s[v];
dp[0][v].max_strenght = s[v];
for (int j = 1; j < maxlog; j ++)
{
dp[j][v].sum = dp[j - 1][v].sum + dp[j - 1][dp[j - 1][v].ver].sum;
dp[j][v].ver = dp[j - 1][dp[j - 1][v].ver].ver;
dp[j][v].max_strenght = max(dp[j - 1][v].max_strenght, dp[j - 1][dp[j - 1][v].ver].max_strenght);
}
for (int u : child[v])
{
dfs(u);
}
}
void init(int N, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L)
{
n = N;
for (int i = 0; i < n; i ++)
{
s[i] = S[i];
p[i] = P[i];
w[i] = W[i];
l[i] = L[i];
child[w[i]].push_back(i);
}
for (int j = 0; j < maxlog; j ++)
dp[j][n].ver = n;
w[n] = n;
dfs(n);
return;
}
long long simulate(int x, int z)
{
ll strength = z;
while(x != n)
{
if (strength >= s[x])
{
for (int bit = maxlog - 1; bit >= 0; bit --)
{
if (dp[bit][x].max_strenght < strength + s[x])
{
strength += dp[bit][x].sum;
x = dp[bit][x].ver;
}
}
///cout << x << endl;
}
else
{
strength += p[x];
x = l[x];
}
}
return strength;
}
# | 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... |