이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n;
vector<ll>dp;
vector<int>s,p,w,l;
vector<vector<ll>>sum,up;
const int lg=30;
void init(int N, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L) {
swap(n,N);
swap(S,s);
swap(P,p);
swap(W,w);
swap(L,l);
dp.resize(n+1);
dp[n]=0;
for(int i=n-1;i>=0;i--){
dp[i]=dp[w[i]]+s[i];
}
up.assign(lg,vector<ll>(n));
sum.assign(lg,vector<ll>(n,0));
for(int j=0;j<lg;j++){
for(int i=0;i<=n;i++){
if(j==0) up[j][i]=l[i],sum[j][i]=p[i];
else{
up[j][i]=up[j-1][up[j-1][i]];
sum[j][i]=sum[j-1][i]+sum[j-1][up[j-1][i]];
}
}
}
}
long long simulate(int x, int z) {
ll ans=z;
for(int i=lg-1;i>=0;i--){
if(ans+sum[i][x]<s[0]){
ans+=sum[i][x];
x=up[i][x];
}
}
if(ans<s[0]){
ans+=sum[0][x];
x=up[0][x];
}
ans+=dp[x];
return ans;
}
# | 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... |