제출 #929107

#제출 시각아이디문제언어결과실행 시간메모리
929107abcvuitunggio던전 (IOI21_dungeons)C++17
89 / 100
7175 ms1907184 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int base=10,sz=9; const long long INF=1e18; int N,nxt[400001][24][sz+1]; long long mx[400001][24],mn[400001][24][sz],sum[400001][24][sz+1]; vector <int> S,P,ve={1}; void init(int n, vector <int> s, vector <int> p, vector <int> w, vector <int> l){ N=n,S=s,P=p; for (int i=1;i<sz;i++) ve.push_back(ve.back()*base); memset(nxt,-1,sizeof(nxt)); for (int i=0;i<n;i++){ for (int j=0;j<sz;j++) if (s[i]<=ve[j]){ nxt[i][0][j]=w[i]; sum[i][0][j]=s[i]; mn[i][0][j]=INF; } else{ nxt[i][0][j]=l[i]; sum[i][0][j]=p[i]; mn[i][0][j]=s[i]; } nxt[i][0][sz]=w[i]; mx[i][0]=sum[i][0][sz]=s[i]; } for (int j=1;j<24;j++){ for (int i=0;i<n;i++) for (int k=0;k<=sz;k++){ if (nxt[i][j-1][k]==-1) continue; int u=nxt[i][j-1][k]; nxt[i][j][k]=nxt[u][j-1][k]; if (k<sz) mn[i][j][k]=min(mn[i][j-1][k],mn[u][j-1][k]-sum[i][j-1][k]); else mx[i][j]=max(mx[i][j-1],mx[u][j-1]-sum[i][j-1][k]); sum[i][j][k]=sum[i][j-1][k]+sum[u][j-1][k]; } } } long long simulate(int x, int Z){ int b=0,cur=0; long long z=Z; while (x<N){ while (cur<sz&&ve[cur]<=z) cur++; int j=(b?cur-1:sz); for (int i=23;i>=0;i--) if (nxt[x][i][j]!=-1) if ((b&&z<mn[x][i][j])||(!b&&z>=mx[x][i])){ z+=sum[x][i][j]; x=nxt[x][i][j]; } b^=1; } return z; }
#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...