이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
#define fr first
#define sc second
typedef long long ll;
using namespace std;
int bs = 5;
const int nop = 5;
const int noa = 19;
int INF = 1e9+7;
ll add[400005] = {0};
pair<int,pair<int,ll>> jump[nop][noa][400005];
int N;
vector<int> S,P,W,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;
S.push_back(INF);
P.push_back(INF);
W.push_back(n);
L.push_back(n);
for(int i=n-1; i>=0; i--) add[i] = add[W[i]] + S[i];
for(int ph=0; ph<nop; ph++)
{
ll l = 1<<(bs*ph);
ll r = 1<<(bs*(ph+1));
for(int i=0; i<=n; i++)
{
if ((l<S[i] && S[i]<r) || i==n) jump[ph][0][i] = {L[i], {S[i], P[i]}};
else if (S[i]<=l) jump[ph][0][i] = {W[i], {INF, S[i]}};
else jump[ph][0][i] = {L[i], {INF, P[i]}};
}
for(int b=1; b<noa; b++)
{
for (int i=0; i<=n; i++)
{
int pos = i;
ll min_S = INF, str_add = 0;
for (int it=0; it<2; it++)
{
auto pr = jump[ph][b-1][pos];
min_S = min(min_S, pr.sc.fr-str_add);
str_add += pr.sc.sc;
pos = pr.fr;
}
jump[ph][b][i] = {pos, {min_S, str_add}};
}
}
}
return;
}
ll simulate(int x, int z)
{
int pos = x;
ll str = z;
for(int a=0; a<nop; a++)
{
ll l = 1<<(bs*a);
ll r = 1<<(bs*(a+1));
while(pos!=N && l<=str && str<r)
{
for(int b=noa-1; b>=0; b--)
{
while(str+jump[a][b][pos].sc.sc < r && str-jump[a][b][pos].sc.fr < 0)
{
str += jump[a][b][pos].sc.sc;
pos = jump[a][b][pos].fr;
}
}
if(pos!=N)
{
if(str>=S[pos]) str += S[pos], pos = W[pos];
else str += P[pos], pos = L[pos];
}
}
}
str += add[pos];
return str;
}
# | 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... |