이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
int n;
vector<signed> s, p, w, l;
pair<int, pair<int, int>> win[400005][25];
pair<int, pair<int, int>> los[400005][25];
void init(signed N, std::vector<signed> S, std::vector<signed> P, std::vector<signed> W, std::vector<signed> L) {
n = N, s = S, p = P, w = W, l = L;
for (int i = 0; i < n; ++i) {
win[i][0] = {s[i], {s[i], w[i]}};
los[i][0] = {s[i] - 1, {p[i], l[i]}};
}
for (int j = 1; j < 24; ++j) {
for (int i = 0; i < n; ++i) {
if (win[i][j - 1].second.second == n) {
win[i][j] = win[i][j - 1];
} else {
auto lft = win[i][j - 1];
auto rgt = win[win[i][j - 1].second.second][j - 1];
int aft = lft.first + lft.second.first;
win[i][j] = {lft.first + max(0ll, 1ll * rgt.first - aft), {lft.second.first + rgt.second.first, rgt.second.second}};
}
if (los[i][j - 1].second.second == n) {
los[i][j] = los[i][j - 1];
} else {
auto lft = los[i][j - 1];
auto rgt = los[lft.second.second][j - 1];
int aft = lft.first + lft.second.first;
los[i][j] = {lft.first - max(0ll, 1ll * aft - rgt.first), {lft.second.first + rgt.second.first, rgt.second.second}};
}
}
}
return;
}
long long simulate(signed x, signed Z) {
// int ans = 0;
ll z = Z;
while (x != n) {
for (int i = 23; i >= 0; --i) {
if (x == n) break;
if (win[x][i].first <= z) {
auto cur = win[x][i];
x = cur.second.second;
z += cur.second.first;
}
}
for (int i = 23; i >= 0; --i) {
if (x == n) break;
if (los[x][i].first >= z) {
auto cur = los[x][i];
x = cur.second.second;
z += cur.second.first;
}
}
}
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... |