제출 #623296

#제출 시각아이디문제언어결과실행 시간메모리
623296Koosha_mv던전 (IOI21_dungeons)C++17
100 / 100
3961 ms814364 KiB
#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=400400,lg=25,S=4; const ll inf=1e18+99; int n; int par[S][N][lg]; ll Min[S][N][lg]; ll prt[S][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); w.pb(-1); t.pb(-1); p.pb(-1); f(l,0,S){ f(i,0,n+1){ if(s[i]<=(1<<(l<<3))){ 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]; if(Min[l][nxt][j-1]<inf){ Min[l][i][j]=min(Min[l][i][j-1],(ll)(max(0ll,Min[l][nxt][j-1]-prt[l][i][j-1]))); } else{ Min[l][i][j]=Min[l][i][j-1]; } } } } } ll simulate(int pos,int _val){ int l=0; ll val=_val; while(1){ while((1<<((l+1)<<3))<=val && l+1<S) 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 2 2 6 9 3 1 2 2 2 3 1 0 1 0 1 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...