이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |