이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int inf = 1e9 + 7;
constexpr int maxn = 4e5 + 5, lg1 = 15, lg2 = 20, add = 10;
struct Move {
int ind;
int start;
long long sum;
Move() {
ind = -1;
sum = 0;
start = 0;
}
};
Move go[lg1][lg2][maxn];
int n;
int s[maxn], p[maxn], w[maxn], l[maxn];
void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, 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];
for (int j = 0; j < lg1; ++j) {
if (s[i] <= (1 << (j + add))) {
go[j][0][i].ind = w[i];
go[j][0][i].sum = s[i];
go[j][0][i].start = inf;
} else {
go[j][0][i].ind = l[i];
go[j][0][i].sum = p[i];
go[j][0][i].start = s[i];
}
}
}
for (int i = 0; i < lg1; ++i) {
for (int j = 1; j < lg2; ++j) {
for (int k = 0; k < n; ++k) {
if (go[i][j - 1][k].ind == -1 || go[i][j - 1][go[i][j - 1][k].ind].ind == -1) {
go[i][j][k].ind = -1;
} else {
go[i][j][k].ind = go[i][j - 1][go[i][j - 1][k].ind].ind;
go[i][j][k].sum = go[i][j - 1][k].sum + go[i][j - 1][go[i][j - 1][k].ind].sum;
go[i][j][k].start = go[i][j - 1][k].start;
if (go[i][j - 1][go[i][j - 1][k].ind].start != inf) {
go[i][j][k].start = min(go[i][j - 1][k].start, (int)max(0LL, go[i][j - 1][go[i][j - 1][k].ind].start - go[i][j - 1][k].sum));
}
}
}
}
}
}
long long simulate(int x, int z) {
int pos = x;
long long sum = z;
while (sum < (1 << add) && pos < n) {
if (s[pos] <= sum) {
sum += s[pos];
pos = w[pos];
} else {
sum += p[pos];
pos = l[pos];
}
}
if (sum == 1) {
if (s[pos] == 1) {
sum += s[pos];
pos = w[pos];
} else {
sum += p[pos];
pos = l[pos];
}
}
while (pos < n) {
int pw = 0;
for (int i = 0; i < lg1; ++i) {
if ((1 << (i + add)) <= sum) {
pw = i;
}
}
while (go[pw][lg2 - 1][pos].ind != -1 && (go[pw][lg2 - 1][pos].start > sum || go[pw][lg2 - 1][pos].start == inf)) {
sum += go[pw][lg2 - 1][pos].sum;
pos = go[pw][lg2 - 1][pos].ind;
}
for (int i = lg2 - 2; i >= 0; --i) {
if (go[pw][i][pos].ind != -1 && (go[pw][i][pos].start > sum || go[pw][i][pos].start == inf)) {
sum += go[pw][i][pos].sum;
pos = go[pw][i][pos].ind;
}
}
if (pos != n) {
sum += s[pos];
pos = w[pos];
}
}
return sum;
}
# | 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... |