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 int N = 5e4 + 10;
const int M = 10000001;
const int INF = 1e7 + 1;
const long long INFF = 1e7 + 1;
const long long INFFF = 100000020000001;
const long long ZERO = 0;
long long dp[N * 24 * 24];
long long NN;
vector <long long> ss, pp, ww, ll;
long long nxt[N];
int lg2[M];
long long f(long long pos, long long strength, long long mindiff) {
return pos * INFFF + strength * INFF + mindiff;
}
long long pos(int i, int j, int k) {
return dp[i * 576 + j * 24 + k] / INFFF;
}
long long strength(int i, int j, int k) {
return (dp[i * 576 + j * 24 + k] / INFF) % INFF;
}
long long mindiff(int i, int j, int k) {
return dp[i * 576 + j * 24 + k] % INFF;
}
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
lg2[1] = 0;
for (int i = 2; i < M; i++) {
lg2[i] = lg2[i / 2] + 1;
}
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]);
}
nxt[n] = 0;
for (int i = n - 1; i >= 0; i--) {
nxt[i] = s[i] + nxt[w[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 < 24; k++) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j < 24; j++) {
if (k == 0) {
int a = ((1 << j) >= s[i]) ? w[i] : l[i];
int b = ((1 << j) >= s[i]) ? s[i] : p[i];
int c = ((1 << j) < s[i]) ? s[i] : INF;
dp[i * 576 + j * 24 + k] = f(a, b, c);
}
else {
int v = pos(i, j, k - 1);
dp[i * 576 + j * 24 + k] = f(pos(v, j, k - 1), min(INFF - 1, strength(i, j, k - 1) + strength(v, j, k - 1)), max(ZERO, min(mindiff(i, j, k - 1), mindiff(v, j, k - 1) - strength(i, j, k - 1))));
}
}
}
}
}
long long simulate(int xx, int zz) {
long long x = xx, z = zz;
while (1) {
int v = lg2[z];
if (z >= 10000000) {
z += nxt[x];
return z;
}
for (int k = 23; k >= 0; k--) {
if (pos(x, v, k) == NN || mindiff(x, v, k) <= z || (z + strength(x, v, k) >= 10000000) || lg2[z + strength(x, v, k)] > v) continue;
z += strength(x, v, k);
x = pos(x, v, k);
}
if (z >= ss[x]) {
z += ss[x];
x = ww[x];
}
else {
z += pp[x];
x = ll[x];
}
if (x == NN) 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... |