이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "dungeons.h"
#pragma GCC target ("popcnt")
using namespace std;
typedef long long ll;
const int N=400001;
int n;
int s[N];
int p[N];
int w[N];
int l[N];
int jump[N][13][12];
ll boost[N][13][12];
ll mn[N][13][12];
int won[N];
int to[N];
int pw[N];
const ll inf=(1ll<<60);
const int lim=10000000;
void chmin(ll &a,ll b){a=min(a,b);}
int msb(ll a)
{
int b=63-__builtin_clzll(a);
return (b/2);
}
void build(int lvl)
{
for(int i=0;i<n;i++)
{
won[i]=(msb(s[i])<=lvl);
to[i]=(won[i]==1?w[i]:l[i]);
pw[i]=(won[i]==1?s[i]:p[i]);
}
won[n]=1; to[n]=n; pw[n]=0;
//j=0
for(int i=0;i<=n;i++)
{
jump[i][lvl][0]=to[i];
boost[i][lvl][0]=pw[i];
mn[i][lvl][0]=(won[i]==0?s[i]:inf);
}
//j>0
for(int j=1;j<12;j++)
{
for(int i=0;i<=n;i++)
{
int a=i;
ll b=0;
ll m=inf;
for(int k=0;k<4;k++)
{
chmin(m,mn[a][lvl][j-1]-b);
b+=boost[a][lvl][j-1];
a=jump[a][lvl][j-1];
}
jump[i][lvl][j]=a;
boost[i][lvl][j]=b;
mn[i][lvl][j]=m;
}
}
}
void init(int tn,vector<int> ts,vector<int> tp,vector<int> tw,vector<int> tl)
{
n=tn;
for(int i=0;i<n;i++){s[i]=ts[i]; p[i]=tp[i]; w[i]=tw[i]; l[i]=tl[i];}
for(int i=0;i<=12;i++) build(i);
}
ll simulate(int a,int z)
{
ll b=z;
auto mv=[&]()
{
if(b>=s[a])
{
b+=s[a];
a=w[a];
}
else
{
b+=p[a];
a=l[a];
}
};
while(b<=63)
{
mv();
if(a==n) return b;
}
while(a!=n)
{
int lvl=min(msb(b)-1,12);
while(a!=n&&min(msb(b)-1,12)==lvl)
{
for(int j=11;j>=0;j--)
{
for(int k=0;k<3;k++)
{
if(jump[a][lvl][j]!=n&&b<mn[a][lvl][j])
{
b+=boost[a][lvl][j];
a=jump[a][lvl][j];
}
}
}
mv();
}
}
return b;
}
# | 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... |