Submission #443537

#TimeUsernameProblemLanguageResultExecution timeMemory
443537JvThunderDungeons Game (IOI21_dungeons)C++17
100 / 100
2796 ms915540 KiB
#include "dungeons.h" #include <bits/stdc++.h> #define fr first #define sc second typedef long long ll; using namespace std; int bs = 5; const int nop = 5; const int noa = 19; int IN = 1e9+7; ll a[400005] = {0}; pair<int,pair<int,ll>> jump[nop][noa][400005]; int N; vector<int> S,P,W,L; void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { S = s; P = p; W = w; L = l; N = n; S.push_back(IN); P.push_back(IN); W.push_back(n); L.push_back(n); for(int i=n-1; i>=0; i--) a[i] = a[W[i]] + S[i]; for(int ph=0; ph<nop; ph++) { ll l = 1<<(bs*ph); ll r = 1<<(bs*(ph+1)); for(int i=0; i<=n; i++) { if ((l<S[i] && S[i]<r) || i==n) jump[ph][0][i] = {L[i], {S[i], P[i]}}; else if (S[i]<=l) jump[ph][0][i] = {W[i], {IN, S[i]}}; else jump[ph][0][i] = {L[i], {IN, P[i]}}; } for(int b=1; b<noa; b++) { for (int i=0; i<=n; i++) { int pos = i; ll min_S = IN, str_a = 0; for (int it=0; it<2; it++) { auto pr = jump[ph][b-1][pos]; min_S = min(min_S, pr.sc.fr-str_a); str_a += pr.sc.sc; pos = pr.fr; } jump[ph][b][i] = {pos, {min_S, str_a}}; } } } return; } ll simulate(int x, int z) { int pos = x; ll str = z; for(int a=0; a<nop; a++) { ll l = 1<<(bs*a); ll r = 1<<(bs*(a+1)); while(pos!=N && l<=str && str<r) { for(int b=noa-1; b>=0; b--) { while(str+jump[a][b][pos].sc.sc < r && str-jump[a][b][pos].sc.fr < 0) { str += jump[a][b][pos].sc.sc; pos = jump[a][b][pos].fr; } } if(pos!=N) { if(str>=S[pos]) str += S[pos], pos = W[pos]; else str += P[pos], pos = L[pos]; } } } str += a[pos]; return str; }
#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...