Submission #921291

#TimeUsernameProblemLanguageResultExecution timeMemory
921291byunjaewooDungeons Game (IOI21_dungeons)C++17
63 / 100
4645 ms2097152 KiB
#include "dungeons.h" #pragma gcc optimize("O3") #include <bits/stdc++.h> using namespace std; using ll=long long; const int Nmax=400001; int N, S[Nmax], P[Nmax], W[Nmax], L[Nmax]; ll DP[Nmax]; vector<int> nxt[24][Nmax], mx[24][Nmax], sum[24][Nmax]; void init(int n, std::vector<int> S_, std::vector<int> P_, std::vector<int> W_, std::vector<int> L_) { N=n; for(int i=0; i<N; i++) S[i]=S_[i], P[i]=P_[i], W[i]=W_[i], L[i]=L_[i]; for(int i=0; i<24; i++) for(int j=0; j<=N; j++) nxt[i][j].resize(i), mx[i][j].resize(i), sum[i][j].resize(i); for(int i=1; i<24; i++) { for(int j=0; j<N; j++) { if(S[j]>=(1<<(i+1))) nxt[i][j][0]=L[j], sum[i][j][0]=P[j], mx[i][j][0]=(1<<(i+1))-1-P[j]; else if(S[j]<=(1<<i)) nxt[i][j][0]=W[j], sum[i][j][0]=S[j], mx[i][j][0]=(1<<(i+1))-1-S[j]; else nxt[i][j][0]=L[j], sum[i][j][0]=P[j], mx[i][j][0]=min(S[j]-1, (1<<(i+1))-1-P[j]); } nxt[i][N][0]=N, sum[i][N][0]=0, mx[i][N][0]=(1<<(i+1))-1; for(int j=1; j<i; j++) for(int k=0; k<=N; k++) { nxt[i][k][j]=nxt[i][nxt[i][k][j-1]][j-1]; sum[i][k][j]=sum[i][k][j-1]+sum[i][nxt[i][k][j-1]][j-1]; if(sum[i][k][j]>1000000000) sum[i][k][j]=1000000000; mx[i][k][j]=min(mx[i][k][j-1], mx[i][nxt[i][k][j-1]][j-1]-sum[i][k][j-1]); } } for(int i=N-1; i>=0; i--) DP[i]=DP[W[i]]+S[i]; } long long simulate(int x, int z) { int k=x; ll v=z; for(int i=0; i<24; i++) { int kk=k; ll vv=v; for(int j=i-1; j>=0; j--) if(vv<=mx[i][kk][j]) { vv+=sum[i][kk][j], kk=nxt[i][kk][j]; if(kk==N) break; } if(kk==N) { for(int j=i-1; j>=0; j--) if(nxt[i][k][j]!=N) v+=sum[i][k][j], k=nxt[i][k][j]; if(k!=N) v+=sum[i][k][0], k=nxt[i][k][0]; return v; } if(vv<(1<<(i+1))) { if(vv>=S[kk]) vv+=S[kk], kk=W[kk]; else vv+=P[kk], kk=L[kk]; } k=kk, v=vv; } return v+DP[k]; }

Compilation message (stderr)

dungeons.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    2 | #pragma gcc optimize("O3")
      |
#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...