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>
#define mindiff first
#define pos second.first
#define strength second.second
using namespace std;
const long long N = 4e5 + 10;
const long long INF = 3e18 + 10;
pair<long long, pair<int, long long>> dp[N][25][8];
long long NN;
vector <long long> ss, pp, ww, ll;
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
NN = n;
s.push_back(0);
p.push_back(0);
w.push_back(n);
l.push_back(n);
for (int i = 0; i <= n; i++) {
ss.push_back(s[i]);
}
for (int i = 0; i <= n; i++) {
pp.push_back(p[i]);
}
for (int i = 0; i <= n; i++) {
ww.push_back(w[i]);
}
for (int i = 0; i <= n; i++) {
ll.push_back(l[i]);
}
for (int k = 0; k < 8; k++) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j < 25; j++) {
if (k == 0) {
dp[i][j][k].pos = ((1 << j) >= s[i]) ? w[i] : l[i];
dp[i][j][k].strength = ((1 << j) >= s[i]) ? s[i] : p[i];
dp[i][j][k].mindiff = ((1 << j) < s[i]) ? s[i] : INF;
}
else {
long long q = 7, p = dp[i][j][k - 1].pos, sm = 0;
while (q--) {
p = dp[p][j][k - 1].pos;
}
dp[i][j][k].pos = p;
dp[i][j][k].strength = dp[i][j][k - 1].strength;
q = 7; p = dp[i][j][k - 1].pos;
while (q--) {
dp[i][j][k].strength += dp[p][j][k - 1].strength;
p = dp[p][j][k - 1].pos;
}
dp[i][j][k].mindiff = dp[i][j][k - 1].mindiff;
q = 7; p = dp[i][j][k - 1].pos; sm = dp[i][j][k - 1].strength;
while (q--) {
dp[i][j][k].mindiff = min(dp[i][j][k].mindiff, dp[p][j][k - 1].mindiff - sm);
sm += dp[p][j][k - 1].strength;
p = dp[p][j][k - 1].pos;
}
}
}
}
}
}
long long simulate(int xx, int zz) {
long long x = xx, z = zz;
while (1) {
int v = (int)(log2l(z));
if (v >= 25) {
for (int k = 7; k >= 0; k--) {
if (dp[x][24][k].pos != NN) {
z += dp[x][24][k].strength;
x = dp[x][24][k].pos;
k++;
}
}
z += dp[x][24][0].strength;
return z;
}
for (int k = 7; k >= 0; k--) {
if (dp[x][v][k].pos == NN || dp[x][v][k].mindiff <= z || (long long)(log2l(z + dp[x][v][k].strength)) > v) continue;
z += dp[x][v][k].strength;
x = dp[x][v][k].pos;
k++;
}
if (z >= ss[x]) {
z += ss[x];
x = ww[x];
}
else {
z += pp[x];
x = ll[x];
}
if (x == NN) return z;
}
return 0;
}
//int main() {
// init(3, { 2, 6, 9 }, { 3, 1, 2 }, { 2, 2, 3 }, { 1, 0, 1 });
// cout << simulate(0, 1) << "\n";
// cout << simulate(2, 3) << "\n";
//}
# | 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... |