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 <bits/stdc++.h>
#include "dungeons.h"
using namespace std;
typedef long long ll;
ll n;
vector<int> s1, p, w, l;
vector<ll> s;
vector<vector<vector<pair<ll, ll>>>> jmp;
vector<ll> dp;
void init(int n1, vector<int> s11, vector<int> p1, vector<int> w1, vector<int> l1) {
n = n1; p = p1; w = w1; l = l1; s1 = s11;
vector<int> s22 = s11;
s.clear();
jmp.clear();
sort(s22.begin(), s22.end());
ll prev = -1;
for (int i = 0; i < n; i++) {
if (s22[i] != prev) {
jmp.push_back(vector<vector<pair<ll, ll>>>(n, vector<pair<ll, ll>>(30)));
s.push_back(s22[i]);
prev = s22[i];
}
}
for (int h = 0; h < s.size(); h++) {
for (int i = 0; i < n; i++) {
pair<ll, ll> win = {s[i], w[i]};
pair<ll, ll> lose = {p[i], l[i]};
jmp[h][i][0] = (h > 0 && s1[i] <= s[h-1]) ? win : lose;
if (jmp[h][i][0].second == n) jmp[h][i][0].first = 1ll << 31ll;
}
}
for (int h = 0; h < s.size(); h++) {
for (int j = 1; j < 30; j++) {
for (int i = 0; i < n; i++) {
if (jmp[h][i][j-1].second == n) {
jmp[h][i][j] = {1ll << 31ll, n};
continue;
}
if (jmp[h][jmp[h][i][j-1].second][j-1].second == n) {
jmp[h][i][j] = {1ll << 31ll, n};
continue;
}
jmp[h][i][j] = {jmp[h][jmp[h][i][j-1].second][j-1].first + jmp[h][i][j-1].first,
jmp[h][jmp[h][i][j-1].second][j-1].second};
}
}
}
dp = vector<ll>(n+1);
dp[n] = 0;
for (int i = n-1; i >= 0; i--) {
dp[i] = s1[i] + dp[w[i]];
}
}
ll simulate(int x1, int z1) {
ll i = x1, z = z1;
if (i == n || z >= s.back()) return z + dp[i];
ll h = 0;
while (z < s.back()) {
while (z >= s[h]) h++;
for (int j = 30-1; j >= 0; j--) {
if (z + jmp[h][i][j].first < s[h]) {
z += jmp[h][i][j].first;
i = jmp[h][i][j].second;
}
}
if (z < s[h]) {
z += p[i];
i = l[i];
}
}
z += dp[i];
return z;
}
Compilation message (stderr)
dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int h = 0; h < s.size(); h++) {
| ~~^~~~~~~~~~
dungeons.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int h = 0; h < s.size(); h++) {
| ~~^~~~~~~~~~
# | 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... |