Submission #879802

#TimeUsernameProblemLanguageResultExecution timeMemory
879802abcvuitunggioDungeons Game (IOI21_dungeons)C++17
100 / 100
6275 ms1869620 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int sz=6; const long long INF=1e18; int nxt[400001][24][sz+1]; long long mx[400001][24][sz+1],mn[400001][24][sz+1],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){ S=s; P=p; for (int i=1;i<sz;i++) ve.push_back(ve.back()*15); 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][sz]=s[i]; 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]; mx[i][j][k]=max(mx[i][j-1][k],mx[u][j-1][k]-sum[i][j-1][k]); mn[i][j][k]=min(mn[i][j-1][k],mn[u][j-1][k]-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; long long z=Z; while (nxt[x][0][0]!=-1){ int j=(b?upper_bound(ve.begin(),ve.end(),z)-ve.begin()-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][j])){ 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...