Submission #961801

#TimeUsernameProblemLanguageResultExecution timeMemory
961801WarinchaiDungeons Game (IOI21_dungeons)C++17
63 / 100
3120 ms1208876 KiB
#include "dungeons.h" #include<bits/stdc++.h> using namespace std; int lift[26][26][50005]; long long mn[26][26][50005]; long long dis[26][26][50005]; long long inf=1e18+7; int N; vector<int>W; vector<int>S; vector<int>L; vector<int>P; long long X=0; void init(int n,vector<int> s,vector<int> p,vector<int> w,vector<int> l) { N=n; S=s; W=w; L=l; P=p; //cerr<<"work\n"; for(int i=0;i<=25;i++){ int st=(1<<(i-1))+1; if(i==0)st=1; int en=(1<<i); for(int j=0;j<n;j++){ if(s[j]>en)lift[i][0][j]=l[j],mn[i][0][j]=inf,dis[i][0][j]=p[j]; else if(s[j]>=st)lift[i][0][j]=l[j],mn[i][0][j]=s[j],dis[i][0][j]=p[j]; else lift[i][0][j]=w[j],mn[i][0][j]=inf,dis[i][0][j]=s[j]; } lift[i][0][n]=n; mn[i][0][n]=0; for(int j=1;j<=25;j++){ for(int k=0;k<=n;k++){ //cerr<<i<<" "<<j<<" "<<k<<"\n"; lift[i][j][k]=lift[i][j-1][lift[i][j-1][k]]; dis[i][j][k]=dis[i][j-1][k]+dis[i][j-1][lift[i][j-1][k]]; X=mn[i][j-1][lift[i][j-1][k]]-dis[i][j-1][k]; if(dis[i][j-1][k]>mn[i][j-1][lift[i][j-1][k]])mn[i][j][k]=0; else mn[i][j][k]=min(mn[i][j-1][k],X); } } } //cerr<<"work\n"; return; } long long simulate(int x, int z) { //cerr<<"work\n"; long long c=0,lv=0; long long pow=z; /*while(pow>(1<<c)){ lv=c; c++; }*/ //cerr<<x<<"\n"; //cerr<<lv<<"\n"; while(1){ assert(pow > (1<<(lv-1))); //cerr<<x<<" "<<pow<<"\n"; if(lv==25)return pow+dis[lv][25][x]; for(int i=25;i>=0;i--){ //cerr<<i<<" "<<lv<<" "<<x<<"\n"; if(pow<mn[lv][i][x]&&pow+dis[lv][i][x]<=(1<<lv))pow+=dis[lv][i][x],x=lift[lv][i][x]; } //cerr<<x<<" "<<pow<<"\n\n"; if(x==N)break; if(pow>=S[x])pow+=S[x],x=W[x]; else { pow+=P[x]; x=L[x]; } lv++; } return pow; }

Compilation message (stderr)

dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:49:15: warning: unused variable 'c' [-Wunused-variable]
   49 |     long long c=0,lv=0;
      |               ^
#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...