Submission #929117

#TimeUsernameProblemLanguageResultExecution timeMemory
929117abcvuitunggioDungeons Game (IOI21_dungeons)C++17
100 / 100
3418 ms1883468 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int base=6,sz=9; const long long INF=1e18; int N,nxt[24][400001][sz+1]; long long mx[24][400001],mn[24][400001][sz],sum[24][400001][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[0][i][j]=w[i]; sum[0][i][j]=s[i]; mn[0][i][j]=INF; } else{ nxt[0][i][j]=l[i]; sum[0][i][j]=p[i]; mn[0][i][j]=s[i]; } nxt[0][i][sz]=w[i]; mx[0][i]=sum[0][i][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[j-1][i][k]==-1) continue; int u=nxt[j-1][i][k]; nxt[j][i][k]=nxt[j-1][u][k]; if (k<sz) mn[j][i][k]=min(mn[j-1][i][k],mn[j-1][u][k]-sum[j-1][i][k]); else mx[j][i]=max(mx[j-1][i],mx[j-1][u]-sum[j-1][i][k]); sum[j][i][k]=sum[j-1][i][k]+sum[j-1][u][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[i][x][j]!=-1) if ((b&&z<mn[i][x][j])||(!b&&z>=mx[i][x])){ z+=sum[i][x][j]; x=nxt[i][x][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...