이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dungeons.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=5050,lg=26;
const ll inf=1e18+99;
int n;
int par[lg/2][N][lg];
ll Min[lg/2][N][lg];
ll prt[lg/2][N][lg];
vector<int> s,p,w,t;
void init(int _n,vector<int> _s,vector<int> _p,vector<int> _w,vector<int> _t) {
n=_n;
s=_s,p=_p,w=_w,t=_t;
s.pb((1<<(lg-1)));
w.pb(-1);
t.pb(-1);
p.pb(-1);
f(l,0,lg/2){
f(i,0,n+1){
if(s[i]<=(1<<(l<<1))){
par[l][i][0]=w[i];
prt[l][i][0]=s[i];
Min[l][i][0]=inf;
}
else{
par[l][i][0]=t[i];
prt[l][i][0]=p[i];
Min[l][i][0]=(i==n ? 0 : s[i]);
}
}
f(j,1,lg){
f(i,0,n+1){
int nxt=par[l][i][j-1];
par[l][i][j]=par[l][nxt][j-1];
prt[l][i][j]=prt[l][i][j-1]+prt[l][nxt][j-1];
Min[l][i][j]=Min[l][i][j-1];
if(Min[l][nxt][j-1]<inf){
minm(Min[l][i][j],max(0ll,Min[l][nxt][j-1]-prt[l][i][j-1]));
}
}
}
}
}
ll simulate(int pos,int _val){
int l=0;
ll val=_val;
while(1){
while((1<<(1<<(l+1)))<=val && l+1<lg/2) l++;
//cout<<pos<<" "<<val<<" -> "<<l<<endl;
f_(i,lg-1,0){
if(Min[l][pos][i]>=val){
val+=prt[l][pos][i];
pos=par[l][pos][i];
}
}
if(pos==n) break ;
//cout<<"posval "<<pos<<" "<<val<<endl;
val+=s[pos];
pos=w[pos];
}
return val;
}
/*
3 1
2 6 9
3 1 2
2 2 3
1 0 1
0 1
*/
# | 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... |