이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
using ll = long long;
const int MN = 4e5+10;
const int W = 6; // 6 worlds
const int MUL = 16; // multiplier = 16
const int ML = 25; // 2^25 ~ 3e7
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
int N;
std::vector<int> s, p, w, l;
int jmp[W][MN][ML];
ll delta[W][MN][ML], max[W][MN][ML];
void init(int _N, std::vector<int> _s, std::vector<int> _p, std::vector<int> _w, std::vector<int> _l) {
N=_N;
s=_s, p=_p, w=_w, l=_l;
memset(jmp, -1, sizeof jmp);
int b=1;
for(int v=0;v<W;++v)
{
for(int i=0;i<N;++i)
if(s[i] < b)
{
jmp[v][i][0]=w[i];
delta[v][i][0]=s[i];
max[v][i][0]=INFL;
}
else
{
jmp[v][i][0]=l[i];
delta[v][i][0]=p[i];
max[v][i][0]=s[i]; // >= max -> unexpected; < max -> go ahead
}
for(int j=0;j+1<ML;++j)
for(int i=0;i<N;++i)
if(jmp[v][i][j]!=-1 && jmp[v][jmp[v][i][j]][j]!=-1)
{
int x = jmp[v][i][j];
jmp[v][i][j+1]=jmp[v][x][j];
delta[v][i][j+1]=delta[v][i][j]+delta[v][x][j];
max[v][i][j+1]=std::min(max[v][i][j], max[v][x][j]-delta[v][i][j]);
}
b *= MUL;
}
}
void step(int &n, ll &z)
{
if(n==N) return;
if(z<s[n])
z+=p[n], n=l[n];
else
z+=s[n], n=w[n];
}
void jump(int v, int cut, int &n, ll &z)
{
for(int i=ML-1;i>=0;--i)
if(jmp[v][n][i] != -1 && z<max[v][n][i] && z+delta[v][n][i]<cut) // while isn't necessary here
z+=delta[v][n][i], n=jmp[v][n][i];
}
long long simulate(int n, int _z) {
ll z=_z;
int b=1;
for(int i=0;i<W;++i)
{
b *= MUL;
while(z<b)
{
jump(i, b, n, z);
step(n, z);
if(n==N) return z;
}
}
return z;
}
# | 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... |