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;
typedef long long ll;
#define F first
#define S second
int nn;
vector<int> ss, pp, ww, lll;
vector<vector<pair<int,ll>>> bl;
vector<ll> last;
ll ggg(int x) {
if(~last[x]) return last[x];
return last[x] = ss[x]+ggg(ww[x]);
}
void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) {
nn = n; ss.resize(n); pp.resize(n); ww.resize(n); lll.resize(n);
for(int i = 0; i < n; i++) ss[i] = s[i], pp[i] = p[i], ww[i] = w[i], lll[i] = l[i];
bl.resize(64, vector<pair<int,ll>>(n+1));
bl[0][n] = {0,0};
for(int i = 0; i < n; i++) bl[0][i] = {l[i], p[i]};
for(int i = 1; i < 64; i++) for(int j = 0; j <= n; j++) bl[i][j] = {bl[i-1][bl[i-1][j].F].F, bl[i-1][j].S+bl[i-1][bl[i-1][j].F].S};
last.resize(n+1,-1);
last[n] = 0;
for(int i = 0; i < n; i++) ggg(i);
}
ll simulate(int x, int z) {
ll k = z;
for(int i = 63; i; i--) if(k+bl[i][x].S < ss[0]) k += bl[i][x].S, x = bl[i][x].F;
k += bl[0][x].S; x = bl[0][x].F;
return k+last[x];
}
# | 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... |