제출 #442216

#제출 시각아이디문제언어결과실행 시간메모리
442216SorahISA던전 (IOI21_dungeons)C++17
37 / 100
440 ms207800 KiB
#include "dungeons.h" #pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long // #define double long double using pii = pair<int, int>; template<typename T> using Prior = std::priority_queue<T>; template<typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>; #define X first #define Y second #define eb emplace_back #define pb pop_back #define pf pop_front #define ALL(x) begin(x), end(x) #define RALL(x) rbegin(x), rend(x) namespace { mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 4E5 + 5; const int lgmx = 19; int N; vector<int> S, P, W, L; int anc[lgmx][maxn], max_val[lgmx][maxn], sum_str[lgmx][maxn]; } /// end of namespace void init(int32_t _N, vector<int32_t> _S, vector<int32_t> _P, vector<int32_t> _W, vector<int32_t> _L) { N = _N; for (auto &x : _S) S.eb(x); for (auto &x : _P) P.eb(x); for (auto &x : _W) W.eb(x); for (auto &x : _L) L.eb(x); memset(anc, 0x00, sizeof(anc)); memset(max_val, 0x00, sizeof(max_val)); memset(sum_str, 0x00, sizeof(sum_str)); for (int i = 0; i < N; ++i) { anc[0][i] = W[i]; max_val[0][i] = S[i]; sum_str[0][i] = S[i]; } anc[0][N] = N; for (int lay = 1; lay < lgmx; ++lay) { for (int i = 0; i <= N; ++i) { int par = anc[lay-1][i]; anc[lay][i] = anc[lay-1][par]; max_val[lay][i] = max(max_val[lay-1][i], max_val[lay-1][par]); sum_str[lay][i] = sum_str[lay-1][i] + sum_str[lay-1][par]; } } } int simulate(int32_t now, int32_t Z) { /// s[i] = p[i] /// while (now != N) { // cerr << "now: " << now << " " << Z << "\n"; for (int lay = lgmx-1; lay >= 0 and now != N; --lay) { // cerr << lay << " " << now << " " << max_val[lay][now] << "\n"; if (Z >= max_val[lay][now]) { Z += sum_str[lay][now]; now = anc[lay][now]; } } if (now == N) break; if (Z >= S[now]) Z += S[now], now = W[now]; else Z += P[now], now = L[now]; } return Z; }
#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...