Submission #1066994

#TimeUsernameProblemLanguageResultExecution timeMemory
1066994idasDungeons Game (IOI21_dungeons)C++17
0 / 100
4 ms10076 KiB
#include "bits/stdc++.h" #include "dungeons.h" #define FOR(i, begin, end) for(int i=(begin); i<(end); i++) #define sz(x) ((int)(x).size()) #define pb push_back #define s second #define f first using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const ll MAX=1e15; const int N=4e5, LG=19; int n, s[N], p[N], w[N], l[N], b[LG][LG][N]; ll sm[LG][LG][N]; void init(int N, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L) { n=N; FOR(i, 0, n) s[i]=S[i], p[i]=P[i], w[i]=W[i], l[i]=L[i]; FOR(i, 0, LG) { FOR(k, 0, n) { if((1<<i)>=s[k]) { b[i][0][k]=w[k]; sm[i][0][k]=s[k]; } else { b[i][0][k]=l[k]; sm[i][0][k]=p[k]; } } b[i][0][n]=n; } FOR(i, 1, LG) { FOR(j, 0, LG) { FOR(k, 0, n+1) { b[j][i][k]=b[j][i-1][b[j][i-1][k]]; sm[j][i][k]=sm[j][i-1][k]+sm[j][i-1][b[j][i-1][k]]; sm[j][i][k]=min(sm[j][i][k], MAX); } } } } long long simulate(int x, int Z) { ll z=Z; int in=0; FOR(i, 1, LG) if(z>=(1<<i)) in=i; while(in<LG-1) { for(int i=LG-1; i>=0; i--) { if(z+sm[in][i][x]<(1<<(in+1))) { z+=sm[in][i][x]; x=b[in][i][x]; } } z+=sm[in][0][x]; x=b[in][0][x]; if(x==n) return z; while(in<LG-1 && z>=(1<<(in+1))) in++; } return z+sm[in][LG-1][x]; } /* 3 1 3 3 3 2 1 1 1 2 3 1 0 3 2 237894 3 2 2 6 9 3 1 2 2 2 3 1 0 1 0 2 2 0 5 1 3 3 1 2 2 1 1 1 1 2 1 2 3 4 5 1 2 0 4 3 4 10000000 4 2 2 4 3 8 2 4 3 8 1 3 3 4 1 0 1 4 0 0 3 4 */
#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...