이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define sz(x) (int)(x).size()
int N;
const ll INF = 1LL << 60;
vi S, P;
vector<int> W, L;
vi dpWin;
vvpii dpLos;
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l)
{
N = n;
S.resize(N), P.resize(N);
W = w, L = l;
for (int i = 0; i < N; ++i)
S[i] = s[i], P[i] = p[i];
dpWin.assign(N + 1, INF);
dpWin[N] = 0;
for (int i = N - 1; i >= 0; --i)
dpWin[i] = S[i] + dpWin[W[i]];
dpLos.assign(N, vpii(ceil(log2(S[0]) + 1)));
for (int i = 0; i < N; ++i)
dpLos[i][0] = {L[i], P[i]};
for (int j = 1; j < sz(dpLos.back()); ++j)
for (int i = 0; i < N; ++i)
dpLos[i][j] = {dpLos[dpLos[i][j - 1].first][j - 1].first, dpLos[dpLos[i][j - 1].first][j - 1].second + dpLos[i][j - 1].second};
return;
}
long long simulate(int x, int z)
{
ll ans = z;
for (int j = sz(dpLos.back()) - 1; j >= 0; --j)
{
if (dpLos[x][j].second + ans < S[x])
{
ans += dpLos[x][j].second;
x = dpLos[x][j].first;
}
}
if (ans < S[x])
{
ans += dpLos[x][0].second;
x = dpLos[x][0].first;
}
return ans + dpWin[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... |