제출 #834402

#제출 시각아이디문제언어결과실행 시간메모리
834402Abrar_Al_Samit던전 (IOI21_dungeons)C++17
25 / 100
315 ms178628 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int nax = 4e5 + 3; int n; vector<int>s, p, w, l; long long sum_toN[nax]; vector<int>g[nax]; void dfs(int v, long long sum = 0) { if(v < n) sum += s[v]; sum_toN[v] = sum; for(int u : g[v]) { dfs(u, sum); } } const int lg = 24; long long sp[5][nax][lg], agg[5][nax][lg]; int inv[10]; map<int,int>vls; int tg = 1; void init(int N, vector<int> S, vector<int> P, vector<int> W, vector<int> L) { n = N, s = S, p = P, w = W, l = L; for(int i=0; i<n; ++i) { g[w[i]].push_back(i); } dfs(n); for(int i=0; i<n; ++i) { vls[s[i]] = 1; } for(auto &it : vls) { it.second = tg; inv[tg] = it.first; ++tg; } for(int k=0; k<tg-1; ++k) { for(int i=0; i<n; ++i) { if(vls[s[i]]>k) { sp[k][i][0] = l[i]; agg[k][i][0] = p[i]; } else { sp[k][i][0] = w[i]; agg[k][i][0] = s[i]; } } sp[k][n][0] = n; for(int j=1; j<lg; ++j) { for(int i=0; i<=n; ++i) { sp[k][i][j] = sp[k][sp[k][i][j-1]][j-1]; agg[k][i][j] = agg[k][i][j-1] + agg[k][sp[k][i][j-1]][j-1]; } } } } const int anax = 1e7; long long simulate(int x, int z) { long long cz = z; for(int k=0; k<tg-1; ++k) { for(int j=lg-1; j>=0; --j) { if(cz + agg[k][x][j] < inv[k+1] && sp[k][x][j] < n) { cz += agg[k][x][j]; x = sp[k][x][j]; } } if(cz < inv[k+1]) { cz += agg[k][x][0]; x = sp[k][x][0]; } } cz += sum_toN[x]; return cz; }
#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...