제출 #1074734

#제출 시각아이디문제언어결과실행 시간메모리
1074734vnm06던전 (IOI21_dungeons)C++17
100 / 100
3139 ms814420 KiB
#include "dungeons.h" #include<bits/stdc++.h> using namespace std; int N; vector<int> S, P, W, L; int vert[10][400005][10]; long long jmp[10][400005][10]; long long gran[10][400005][10]; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { N=n; S=s; P=p; W=w; L=l; long long le=1, ri=5; for(int tree=0; tree<10; tree++) { for(int i=0; i<n; i++) { if(s[i]<le) { vert[tree][i][0]=w[i]; jmp[tree][i][0]=s[i]; gran[tree][i][0]=ri; } else if(s[i]>ri) { vert[tree][i][0]=l[i]; jmp[tree][i][0]=p[i]; gran[tree][i][0]=ri; } else { vert[tree][i][0]=l[i]; jmp[tree][i][0]=p[i]; gran[tree][i][0]=s[i]-1; } } for(int lvl=1; lvl<10; lvl++) { for(int i=0; i<n; i++) { vert[tree][i][lvl]=vert[tree][i][lvl-1]; jmp[tree][i][lvl]=jmp[tree][i][lvl-1]; gran[tree][i][lvl]=gran[tree][i][lvl-1]; for(int j=1; j<=5; j++) { int nv=vert[tree][i][lvl]; if(nv==n) break; vert[tree][i][lvl]=vert[tree][nv][lvl-1]; gran[tree][i][lvl]=min(gran[tree][i][lvl], max((long long)0, gran[tree][nv][lvl-1]-jmp[tree][i][lvl])); jmp[tree][i][lvl]+=jmp[tree][nv][lvl-1]; if(gran[tree][i][lvl]<=0) break; } } } le*=6; ri=le*6-1; if(tree==8) ri=1e18; } return; } long long simulate(int x, int z) { int v=x; long long st=z; long long tree=0, le=1, ri=5; int br=0; while(v!=N) { br++; if(br>50) assert(false); while(tree<9 && st>ri) { le*=6; ri=le*6-1; if(tree==8) ri=1e18; tree++; } for(int lvl=9; lvl>=0; lvl--) { for(int j=5;; j--) { if(st<=gran[tree][v][lvl]) { st+=jmp[tree][v][lvl]; v=vert[tree][v][lvl]; if(v==N) break; } else break; } if(v==N) break; } for(int tt=0; tt<5; tt++) { if(v==N) break; if(st<S[v]) { st+=P[v]; v=L[v]; } else { st+=S[v]; v=W[v]; }} } return st; }
#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...