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;
using ll = long long;
const int MAXN = 400000;
const int LOG2 = 24;
//const int LOG4 = 11;
const int LOG8 = 8;
const int INF = 1000000000;
int dp[LOG2+1][MAXN+5][LOG8+1];
ll dod[LOG2+5][MAXN+5][LOG8+1];
int gde[LOG2+5][MAXN+5][LOG8+1];
int s[MAXN+5];
int pl[MAXN+5];
int win[MAXN+5];
int lose[MAXN+5];
int N;
void init(int n, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L){
N = n;
for(int i=0; i<n; i++){
s[i] = S[i];
pl[i] = P[i];
win[i] = W[i];
lose[i] = L[i];
}
s[n] = 0;
pl[n] = 0;
win[n] = n;
lose[n] = n;
for(int k=0; k<=LOG2; k++){
for(int i=0; i<=n; i++){
if((1<<k) >= s[i]){
dp[k][i][0] = INF;
dod[k][i][0] = s[i];
gde[k][i][0] = win[i];
}
else{
dp[k][i][0] = s[i] - 1;
dod[k][i][0] = pl[i];
gde[k][i][0] = lose[i];
}
}
for(int j=1; j<=LOG8; j++){
for(int i=0; i<=n; i++){
int h = gde[k][i][j-1];
int mndp = dp[k][i][j-1];
ll udod = dod[k][i][j-1];
for(int times=1; times<8; times++){
h = gde[k][h][j-1];
mndp = min(1LL*mndp, dp[k][h][j-1] == INF ? INF : dp[k][h][j-1] - min(1LL*INF, udod));
udod += dod[k][h][j-1];
}
gde[k][i][j] = h;
dod[k][i][j] = udod;
dp[k][i][j] = max(mndp, -5);
}
}
}
return;
}
ll simuliraj(int x, ll z){
if(x == N) return z;
int k = 0;
for(int j=0; j<=LOG2; j++){
if((1<<j) <= z) k = j;
}
for(int j=LOG8; j>=0; j--){
for(int times=0; times<8; times++){
if(dp[k][x][j] >= z){
z += dod[k][x][j];
x = gde[k][x][j];
}
}
}
if(x == N) return z;
if(z >= s[x]) return simuliraj(win[x], z + s[x]);
return simuliraj(lose[x], z + pl[x]);
}
long long simulate(int x, int z) {
return simuliraj(x, 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... |