This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18L + 20;
const int maxN = 5e4 + 20;
const int maxT = 24;
const int maxK = 30;
pair<int, pair<long long, long long>> jump[maxT][maxN][maxK];
int S[maxN];
int P[maxN];
int W[maxN];
int L[maxN];
vector<int> times;
int N, T;
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];
}
W[N] = N;
for (int i = 0; i < 23; i++) {
times.push_back(1 << i);
}
T = times.size();
for (int t = 0; t <= T; t++) {
for (int i = 0; i < N; i++) {
if (t == T || S[i] < times[t]) {
jump[t][i][0] = make_pair(W[i], make_pair(S[i], -inf));
}
else {
jump[t][i][0] = make_pair(L[i], make_pair(P[i], -S[i]));
}
}
jump[t][N][0] = make_pair(N, make_pair(0, -inf));
for (int k = 1; k < maxK; k++) {
jump[t][N][k] = make_pair(N, make_pair(0, -inf));
for (int i = 0; i < N; i++) {
int nxt = jump[t][i][k - 1].first;
jump[t][i][k] = make_pair(jump[t][nxt][k - 1].first, make_pair(jump[t][i][k - 1].second.first + jump[t][nxt][k - 1].second.first, max(jump[t][i][k - 1].second.second, jump[t][i][k - 1].second.first + jump[t][nxt][k - 1].second.second)));
}
}
}
return;
}
long long simulate(int X, int _Z) {
long long Z = _Z;
while (X != N) {
int t = upper_bound(times.begin(), times.end(), Z) - times.begin();
for (int k = maxK - 1; k >= 0; k--) {
if (Z + jump[t][X][k].second.second < 0) {
Z += jump[t][X][k].second.first;
X = jump[t][X][k].first;
}
}
/* Z += S[X];
X = W[X];*/
}
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... |