이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
const int kN = 4e5 + 10;
const int kC = 25;
// subtask 3
int n;
vector<int> s, p, w, l;
long long suf[kN];
int climb[2][kC][kN], MAX; // 0: win, 1: lose
long long max_pow[2][kC][kN], gained_pow[2][kC][kN];
void init(int _n, vector<int> _s, vector<int> _p, vector<int> _w, vector<int> _l) {
n = _n, s = _s, p = _p, w = _w, l = _l;
for(int i = n - 1; i >= 0; i--) suf[i] = s[i] + suf[w[i]], MAX = max(MAX, s[i]);
for(int i = 0; i < n; i++) {
climb[0][0][i] = w[i];
climb[1][0][i] = l[i];
max_pow[0][0][i] = s[i];
max_pow[1][0][i] = s[i] - 1;
gained_pow[0][0][i] = s[i];
gained_pow[1][0][i] = p[i];
}
climb[0][0][n] = n;
climb[1][0][n] = n;
for(int j = 1; j < kC; j++) {
for(int i = 0; i <= n; i++) {
climb[0][j][i] = climb[0][j - 1][climb[0][j - 1][i]];
climb[1][j][i] = climb[1][j - 1][climb[1][j - 1][i]];
max_pow[0][j][i] = max(max_pow[0][j - 1][i], max_pow[0][j - 1][climb[0][j - 1][i]] - gained_pow[0][j - 1][i]);
max_pow[1][j][i] = min(max_pow[1][j - 1][i], max_pow[1][j - 1][climb[1][j - 1][i]] - gained_pow[1][j - 1][i]);
gained_pow[0][j][i] = gained_pow[0][j - 1][i] + gained_pow[0][j - 1][climb[0][j - 1][i]];
gained_pow[1][j][i] = gained_pow[1][j - 1][i] + gained_pow[1][j - 1][climb[1][j - 1][i]];
}
}
return;
}
long long simulate(int x, int z) {
long long res = z;
int cnt = 0;
while(x < n) {
cnt++;
bool flag = (res < s[x]);
for(int j = kC - 1; j >= 0; j--) {
auto Check = [&]()->bool {
if(flag) return res > max_pow[flag][j][x];
else return res < max_pow[flag][j][x];
};
if(Check()) continue;
res += gained_pow[flag][j][x], x = climb[flag][j][x];
}
}
return res;
}
# | 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... |