이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "dungeons.h"
using namespace std;
#define ll long long
#define inf 1e12
const int mxn = 4e5 + 10, LOG1 = 25, LOG2 = 9, BASE = 8;
// steps, pwr
int n;
vector<int> s, p, w, l;
int go[mxn][LOG1][LOG2];
ll gain[mxn][LOG1][LOG2], lim[mxn][LOG1][LOG2];
ll F[LOG2];
void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) {
F[0] = 1;
for (int i = 1; i < LOG2; i++) F[i] = F[i - 1] * BASE;
n = _n, s = _s, p = _p, w = _w, l = _l;
for (int pwr = 0; pwr < LOG2; pwr++) {
for (int i = 0; i < n; i++) {
if (F[pwr] >= s[i]) {
if (w[i] == n) go[i][0][pwr] = -1;
else {
go[i][0][pwr] = w[i];
gain[i][0][pwr] = s[i];
lim[i][0][pwr] = inf;
}
}
else {
if (l[i] == n) go[i][0][pwr] = -1;
else {
go[i][0][pwr] = l[i];
gain[i][0][pwr] = p[i];
lim[i][0][pwr] = s[i];
}
}
}
}
for (int steps = 1; steps < LOG1; steps++) {
for (int pwr = 0; pwr < LOG2; pwr++) {
for (int i = 0; i < n; i++) {
int nxt = go[i][steps - 1][pwr];
if (go[i][steps - 1][pwr] == -1 || go[nxt][steps - 1][pwr] == -1) go[i][steps][pwr] = -1;
else {
go[i][steps][pwr] = go[nxt][steps - 1][pwr];
gain[i][steps][pwr] = gain[i][steps - 1][pwr] + gain[nxt][steps - 1][pwr];
lim[i][steps][pwr] = min(lim[i][steps - 1][pwr], lim[nxt][steps - 1][pwr] - gain[i][steps - 1][pwr]);
}
}
}
}
}
ll simulate(int x, int z) {
ll ans = z;
int pwr = 0;
while (x != n) {
while (pwr + 1 < LOG2 && F[pwr + 1] <= ans) pwr++;
for (int i = LOG1 - 1; i >= 0; i--) {
if (go[x][i][pwr] == -1) continue;
if (ans >= lim[x][i][pwr]) continue;
ans += gain[x][i][pwr];
x = go[x][i][pwr];
}
if (ans >= s[x]) {
ans += s[x];
x = w[x];
}
else {
ans += p[x];
x = l[x];
}
}
return ans;
}
# | 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... |