제출 #1245380

#제출 시각아이디문제언어결과실행 시간메모리
1245380countless던전 (IOI21_dungeons)C++20
0 / 100
7092 ms8008 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") typedef long long ll; typedef long double ld; #define sp <<" "<< #define endl "\n" int N; vector<int> S, P, W, L; vector<int> dep; vector<vector<int>> adj; 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; dep.resize(N+1), adj.resize(N+1); for (int i = 0; i < N; i++) { adj[W[i]].push_back(i); } auto dfs = [&](auto &&dfs, int u, int p) -> void { for (auto &v : adj[u]) { if (v != p) { dep[v] = dep[u] + 1; dfs(dfs, v, u); } } }; dfs(dfs, N, -1); return; } ll simulate(int x, int z) { ll at = x, ans = z; vector<bool> vis(N+1); vector<ll> mem(N+1); while (at != N) { // cerr << "i have" sp ans sp "at" sp at << ". i'm fighting against" sp S[at] << endl; if (ans >= S[at]) { return 1LL * dep[at] * S[at] + ans; } else { if (vis[at]) { ll need = S[at] - ans; ll cyc = ans - mem[at]; ll amt = need / cyc; // cerr << "cycle" sp cyc sp need sp amt << endl; if (amt) ans += cyc * amt; else { ans += P[at]; at = L[at]; } // fill(vis.begin(), vis.end(), false); } else { vis[at] = true; mem[at] = ans; ans += P[at]; at = L[at]; } } // cerr << "i'm now at" sp at sp "with" sp ans << endl; // cerr << endl; } return ans; }
#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...