제출 #622798

#제출 시각아이디문제언어결과실행 시간메모리
622798Bench0310던전 (IOI21_dungeons)C++17
37 / 100
7056 ms682112 KiB
#include <bits/stdc++.h> #include "dungeons.h" #pragma GCC target ("popcnt") using namespace std; typedef long long ll; const int C=6; //cutoff between naive jumping and building base-4 jumps const int N=400001; int n; int s[N]; int p[N]; int w[N]; int l[N]; int jump[N][13-C][12]; ll boost[N][13-C][12]; ll mn[N][13-C][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+C); 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-C;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<=(1<<(2*(C+1)))-1) { mv(); if(a==n) return b; } while(a!=n) { int lvl=min(msb(b)-1,12)-C; while(a!=n&&min(msb(b)-1,12)-C==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 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...