이 제출은 이전 버전의 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;
typedef vector<vvpii> vvvpii;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int N;
const ll INF = 1LL << 60;
vi S, P;
vi Svalues;
vector<int> W, L;
vi dpWin;
vvvpii 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];
set<int> shelper(all(S));
Svalues = vi(all(shelper));
dpWin.assign(N + 1, INF);
dpWin[N] = 0;
for (int i = N - 1; i >= 0; --i)
dpWin[i] = S[i] + dpWin[W[i]];
dpLos.resize(sz(Svalues)); // assuming not having reached Svalues[i]
for (int ii = 0; ii < sz(Svalues); ++ii)
{
dpLos[ii] = vvpii(N, vpii(ceil(log2(Svalues[ii]) + 1)));
for (int i = 0; i < N; ++i)
if (S[i] >= Svalues[ii])
dpLos[ii][i][0] = {L[i], P[i]};
else
dpLos[ii][i][0] = {W[i], S[i]};
for (int j = 1; j < sz(dpLos[ii].back()); ++j)
for (int i = 0; i < N; ++i)
{
int mid = dpLos[ii][i][j - 1].first;
if (mid == N)
dpLos[ii][i][j] = dpLos[ii][i][j - 1];
else
dpLos[ii][i][j] = {dpLos[ii][mid][j - 1].first, dpLos[ii][mid][j - 1].second + dpLos[ii][i][j - 1].second};
}
}
return;
}
long long simulate(int x, int z)
{
ll ans = z;
for (int ii = 0; ii < sz(Svalues); ++ii)
{
if (ans >= Svalues[ii])
continue;
for (int j = sz(dpLos[ii].back()) - 1; j >= 0 && x != N; --j)
{
if (dpLos[ii][x][j].second + ans < Svalues[ii])
{
ans += dpLos[ii][x][j].second;
x = dpLos[ii][x][j].first;
}
}
if (ans < Svalues[ii] && x != N)
{
ans += dpLos[ii][x][0].second;
x = dpLos[ii][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... |