이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define loop(x, i) for (int i = 0; i < x; i++)
#define rev(x, i) for (int i = (int)x - 1; i >= 0; i--)
#define loop1(x, i) for (int i = 1; i <= x; i++)
#define ALL(x) begin(x), end(x)
#define pb push_back
#define int long long
typedef vector<int> vi;
typedef vector<signed> vi32;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#include "dungeons.h"
int N;
vi32 S, P, W, L;
vvi winP, winD, maxS;
void init(signed n, vi32 s, vi32 p, vi32 w, vi32 l)
{
N = n;
S = s;
P = p;
W = w;
L = l;
winP = maxS = winD = vvi(30, vi(n + 1));
loop(n, i)
{
winD[0][i] = s[i];
maxS[0][i] = s[i];
winP[0][i] = w[i];
}
winD[0][n] = 0;
maxS[0][n] = 0;
winP[0][n] = n;
loop1(29, x)
{
loop(n + 1, i)
{
int halfW = winP[x - 1][i];
winP[x][i] = winP[x - 1][halfW];
winD[x][i] = winD[x - 1][i] + winD[x - 1][halfW];
maxS[x][i] = max(maxS[x - 1][i], maxS[x - 1][halfW]);
}
}
}
int simulate(signed a, signed b)
{
int x = a, z = b;
auto runLosses = [&]() -> int
{
while (x != N && z < S[x])
{
z += P[x];
x = L[x];
}
if (x == N)
return z;
return -1;
};
while (winP[0][x] != N)
{
rev(30, j)
{
if (winP[j][x] != N && z < maxS[j][x])
{
z += winD[j][x];
x = winP[j][x];
}
}
if (z < S[x])
{
int res = runLosses();
if (res != -1)
return res;
}
}
z += winD[0][x];
x = winP[0][x];
return z;
}
# | 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... |