제출 #615786

#제출 시각아이디문제언어결과실행 시간메모리
615786Clan328던전 (IOI21_dungeons)C++17
0 / 100
1 ms724 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int n; vector<pair<ll, ll>> G, W; vl dp; vl invG, invW; const int LOG = 20; vvi up; vvl sum; vi visited; void dfs(int v, int p) { if (visited[v]) return; visited[v] = true; up[v][0] = p; sum[v][0] = W[v].second; for (int i = 1; i < LOG; i++) { sum[v][i] = sum[v][i-1] + sum[up[v][i-1]][i-1]; up[v][i] = up[up[v][i-1]][i-1]; } dfs(invG[v], v); } ll getDP(int i) { if (dp[i] != -1) return dp[i]; if (i == n) { dp[i] = 0; return 0; } dp[i] = W[i].first+getDP(G[i].first); return dp[i]; } void init(int nx, vi s, vi p, vi w, vi l) { n = nx; G = vector<pll>(n); W = vector<pll>(n); invG = vector<ll>(n); invW = vector<ll>(n); for (int i = 0; i < n; i++) { G[i] = {w[i], l[i]}; W[i] = {s[i], p[i]}; invG[l[i]] = i; invW[l[i]] = p[i]; } dp = vl(n+1, -1); for (int i = 0; i <= n; i++) { dp[i] = getDP(i); } vi par(n); for (int i = 0; i < n; i++) { par[i] = G[i].second; } visited = vi(n); up = vvi(n, vi(LOG)); sum = vvl(n, vl(LOG)); for (int i = 0; i < n; i++) { if (!visited[i]) dfs(i, par[i]); } } ll simulate(int x, int z) { if (z >= W[0].first) { return z + dp[x]; } ll strength = z; for (int i = LOG-1; i >= 0; i--) { if (sum[x][i]+strength < W[0].first) { strength += sum[x][i]; x = up[x][i]; } } return strength+sum[x][0]+dp[up[x][0]]; }
#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...