이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "dungeons.h"
using namespace std;
const int mxN = (int)5e4+5;
const int lg = (int)32;
long long lim[mxN][lg][32];
long long gget[mxN][lg][32];
int jump[mxN][lg][32];
int N;
vector<int>S; vector<int>P; vector<int>W; vector<int>L;
void init(int n, vector<int>s, vector<int>p, vector<int>w, vector<int>l) {
S = s, P = p, W = w, L = l;
N = n;
for(int j = 0 ; j < lg ; j++) {
for(int i = 0 ; i < n ; i++) {
if(pow(2,j) >= s[i]) {
lim[i][j][0] = LLONG_MAX;
gget[i][j][0] = s[i];
jump[i][j][0] = w[i];
} else {
lim[i][j][0] = s[i];
gget[i][j][0] = p[i];
jump[i][j][0] = l[i];
}
}
}
for(int k = 1 ; k < 30 ; k++) {
for(int j = 0 ; j < lg ; j++) {
for(int i = 0 ; i < n ; i++) {
lim[i][j][k] = (lim[i][j][k-1] == LLONG_MAX && lim[ jump[i][j][k-1] ][j][k-1] - gget[i][j][k-1] == LLONG_MAX ? LLONG_MAX : min(lim[i][j][k-1], lim[ jump[i][j][k-1] ][j][k-1] - gget[i][j][k-1]));
gget[i][j][k] = gget[i][j][k-1] + gget[ jump[i][j][k-1] ][j][k-1];
jump[i][j][k] = jump[ jump[i][j][k-1] ][j][k-1];
}
}
}
}
long long simulate(int x, int z) {
long long c = z;
int pw = 0;
while(x != N) {
while(pow(2,(pw+1)) <= c && pw+1 <= 30) {
pw++;
}
for(int j = 30 ; j >= 0 ; j--) {
if(lim[x][pw][j] > c && jump[x][pw][j] != N) {
c += gget[x][pw][j];
x = jump[x][pw][j];
}
}
if(x != N) {
if(c >= S[x]) {
c += S[x];
x = W[x];
} else {
c += P[x];
x = L[x];
}
}
}
return c;
}
# | 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... |