이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 4 * (int)1e5;
const int C0 = 8;
const int C1 = 1;
const int H = 24;
const ll INF = 1e9 + 7;
pair<int, pair<ll, ll>> jmp[N + 1][H / C0][H / C1];
ll add[N + 1];
ll str[N + 1];
ll bns[N + 1];
int wt[N + 1];
int lt[N + 1];
int n;
pair<int, ll> advance(pair<int, ll> cur) {
if (str[cur.first] > cur.second) return {lt[cur.first], bns[cur.first] + cur.second};
else return {wt[cur.first], str[cur.first] + cur.second};
}
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) str[i] = s[i];
for (int i = 0; i < n; ++i) bns[i] = p[i];
for (int i = 0; i < n; ++i) wt[i] = w[i];
for (int i = 0; i < n; ++i) lt[i] = l[i];
str[n] = INF;
bns[n] = INF;
wt[n] = n;
lt[n] = n;
add[n] = 0;
for (int i = n-1; i >= 0; --i) add[i] = add[wt[i]] + str[i];
for (int a = 0; a < H / C0; ++a) {
ll lo = 1 << (C0 * a);
ll hi = 1 << (C0 * (a + 1));
for (int i = 0; i <= n; ++i) {
if ((lo < str[i] && str[i] < hi) || i == n) {
jmp[i][a][0] = {lt[i], {str[i], bns[i]}};
} else if (str[i] <= lo) {
jmp[i][a][0] = {wt[i], {INF, str[i]}};
} else {
jmp[i][a][0] = {lt[i], {INF, bns[i]}};
}
}
for (int b = 1; b < H / C1; ++b) {
for (int i = 0; i <= n; ++i) {
int j = i;
ll min_str = INF, str_add = 0;
for (int it = 0; it < (1 << C1); ++it) {
auto pr = jmp[j][a][b - 1];
min_str = min(min_str, pr.second.first - str_add);
str_add += pr.second.second;
j = pr.first;
}
jmp[i][a][b] = {j, {min_str, str_add}};
}
}
}
}
long long simulate(int start_i, int ini_pwr) {
pair<int, ll> state = {start_i, (ll)ini_pwr};
for (int a = 0; a < H; ++a) {
ll lo = 1 << (C0 * a);
ll hi = 1 << (C0 * (a + 1));
while(state.first != n && lo <= state.second && state.second < hi) {
for (int b = (H/C1) - 1; b >= 0; --b) {
while(state.second < jmp[state.first][a][b].second.first && state.second + jmp[state.first][a][b].second.second < hi) {
state.second += jmp[state.first][a][b].second.second;
state.first = jmp[state.first][a][b].first;
}
}
if (state.first != n) state = advance(state); // either win against opponent in same strength bracket, or break out of strength bracket
}
}
return state.second + add[state.first];
}
# | 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... |