제출 #443534

#제출 시각아이디문제언어결과실행 시간메모리
443534JvThunder던전 (IOI21_dungeons)C++17
100 / 100
2624 ms915604 KiB
#include "dungeons.h" #include <bits/stdc++.h> #define fir first #define sec second typedef long long ll; using namespace std; int base = 5; const int nop = 5; const int noa = 19; const int sz = 400005; int INF = 1e9+7; ll add[sz] = {0}; pair<int,pair<int,ll>> jump[nop][noa][sz]; 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(INF); P.push_back(INF); W.push_back(n); L.push_back(n); for(int i=n-1; i>=0; i--) add[i] = add[W[i]] + S[i]; for(int ph=0; ph<nop; ph++) { ll l = 1<<(base*ph); ll r = 1<<(base*(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], {INF, S[i]}}; else jump[ph][0][i] = {L[i], {INF, P[i]}}; } for(int b=1; b<noa; b++) { for (int i=0; i<=n; i++) { int pos = i; ll min_S = INF, str_add = 0; for (int it=0; it<2; it++) { auto pr = jump[ph][b-1][pos]; min_S = min(min_S, pr.sec.fir-str_add); str_add += pr.sec.sec; pos = pr.first; } jump[ph][b][i] = {pos, {min_S, str_add}}; } } } return; } ll simulate(int x, int z) { int pos = x; ll str = z; for(int a=0; a<nop; a++) { ll l = 1<<(base*a); ll r = 1<<(base*(a+1)); while(pos!=N && l<=str && str<r) { for(int b=noa-1; b>=0; b--) { while(str+jump[a][b][pos].sec.sec < r && str-jump[a][b][pos].sec.fir < 0) { str += jump[a][b][pos].sec.sec; pos = jump[a][b][pos].fir; } } if(pos!=N) { if(str>=S[pos]) str += S[pos], pos = W[pos]; else str += P[pos], pos = L[pos]; } } } str += add[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...