제출 #1242923

#제출 시각아이디문제언어결과실행 시간메모리
1242923trimkus던전 (IOI21_dungeons)C++20
13 / 100
934 ms19616 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> S, P, W, L; int N; const int MAXN = 5e4 + 1; vector<int> adj[MAXN + 1]; ll cost[MAXN + 1]; ll cycle_cost[MAXN + 1]; bool cycle[MAXN + 1]; int lift[MAXN + 1][20], lift1[MAXN + 1][20]; ll cost1[MAXN + 1][20]; ll cyc_cost[MAXN + 1][20]; int len[MAXN + 1]; void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) { N = n; S = s; P = p; W = w; L = l; S.push_back(0); for (int i = 0; i < n; ++i) { adj[w[i]].push_back(i); } auto dfs = [&](auto& dfs, int i, ll now) -> void { now += S[i]; cost[i] = now; for (auto& u : adj[i]) { dfs(dfs, u, now); } }; dfs(dfs, n, 0); // for (int i = 0; i < n; ++i) { // cerr << cost[i] << " "; // } // cerr << "\n"; for (int i = 0; i <= n; ++i) { for (int j = 0; j < 20; ++j) { lift[i][j] = -1; cost1[i][j] = 1e18; } } // for (int i = 0; i < n; ++i) { // if (cycle[i]) { // cerr << i << " "; // } // } // cerr << "\n"; for (int i = 0; i < n; ++i) { lift[i][0] = L[i]; cost1[i][0] = P[i]; } for (int j = 1; j < 20; ++j) { for (int i = 0; i < n; ++i) { if (lift[i][j - 1] == -1) continue; // cerr << i << "!\n"; lift[i][j] = lift[lift[i][j - 1]][j - 1]; cost1[i][j] = cost1[i][j - 1] + cost1[lift[i][j - 1]][j - 1]; } } // for (int j = 0; j < 5; ++j) { // for (int i = 0; i <= n; ++i) { // cout << lift[i][j] << " "; // } // cout << "\n"; // } // for (int j = 0; j < 5; ++j) { // for (int i = 0; i <= n; ++i) { // cout << cost1[i][j] << " "; // } // cout << "\n"; // } // for (int i = 0; i <= n; ++i) { // cout << cycle[i] << " "; // } // cout << "\n"; return; } long long simulate(int x, int z) { ll res = z; ll tot = 0; // cout << x << " -> "; while (res < S[0] && x != N) { for (int i = 19; i >= 0; --i) { if (lift[x][i] == -1) continue; if (cost1[x][i] + res >= S[0]) continue; res += cost1[x][i]; x = lift[x][i]; } if (x == N) break; res += cost1[x][0]; x = lift[x][0]; } if (x == N) return res; res += cost[x]; return res; }
#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...