이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
const int nax = 4e5 + 3;
int n;
vector<int>s, p, w, l;
long long sum_toN[nax];
vector<int>g[nax];
void dfs(int v, long long sum = 0) {
if(v < n) sum += s[v];
sum_toN[v] = sum;
for(int u : g[v]) {
dfs(u, sum);
}
}
const int lg = 24;
long long sp[5][nax][lg], agg[5][nax][lg];
int inv[10];
map<int,int>vls;
int tg = 1;
void init(int N, vector<int> S, vector<int> P, vector<int> W, vector<int> L) {
n = N, s = S, p = P, w = W, l = L;
for(int i=0; i<n; ++i) {
g[w[i]].push_back(i);
}
dfs(n);
for(int i=0; i<n; ++i) {
vls[s[i]] = 1;
}
for(auto &it : vls) {
it.second = tg;
inv[tg] = it.first;
++tg;
}
for(int k=0; k<tg-1; ++k) {
for(int i=0; i<n; ++i) {
if(vls[s[i]]>k) {
sp[k][i][0] = l[i];
agg[k][i][0] = p[i];
} else {
sp[k][i][0] = w[i];
agg[k][i][0] = s[i];
}
}
sp[k][n][0] = n;
for(int j=1; j<lg; ++j) {
for(int i=0; i<=n; ++i) {
sp[k][i][j] = sp[k][sp[k][i][j-1]][j-1];
agg[k][i][j] = agg[k][i][j-1] + agg[k][sp[k][i][j-1]][j-1];
}
}
}
}
const int anax = 1e7;
long long simulate(int x, int z) {
long long cz = z;
for(int k=0; k<tg-1; ++k) {
for(int j=lg-1; j>=0; --j) {
if(cz + agg[k][x][j] < inv[k+1] && sp[k][x][j] < n) {
cz += agg[k][x][j];
x = sp[k][x][j];
}
}
if(cz < inv[k+1]) {
cz += agg[k][x][0];
x = sp[k][x][0];
}
}
cz += sum_toN[x];
return cz;
}
# | 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... |