제출 #1287615

#제출 시각아이디문제언어결과실행 시간메모리
1287615SamueleVidThe short shank; Redemption (BOI21_prison)C++20
0 / 100
84 ms53884 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define rep(i,a,b) for(int i = a; i < (b); ++i) typedef long long ll; #define sz(x) (int)(x).size() typedef vector<int> vi; typedef pair<int, int> pii; void dfs(int u, vector<vi> &adj, vi &height, vi &max_depth_node) { max_depth_node[u] = u; height[u] = 1; for (auto x : adj[u]) { dfs(x, adj, height, max_depth_node); if (height[x] + 1 > height[u]) { height[u] = height[x] + 1; max_depth_node[u] = max_depth_node[x]; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, D, T; cin >> N >> D >> T; vector<ll> t(N); for (int i = 0; i < N; i ++) cin >> t[i]; vi is_passive(N); ll curr_min = 1e18; for (int i = 0; i < N; i ++) { curr_min = min(curr_min + 1, t[i]); if (t[i] > T && curr_min <= T) is_passive[i] = 1; } vi p(N, -1); vi passive_without_parent; curr_min = 1e18; for (int i = 0; i < N; i ++) { if (is_passive[i]) { if (curr_min <= T) { for (auto x : passive_without_parent) { p[x] = i; } passive_without_parent.clear(); curr_min = 1e18; } passive_without_parent.push_back(i); } else { curr_min = min(curr_min + 1, t[i]); } } vector<vi> adj(N); for (int i = 0; i < N; i ++) { if (!is_passive[i]) continue; if (p[i] != -1) adj[p[i]].push_back(i); } vi height(N), max_depth_node(N); vector<vi> roots_at_depth(N); for (int i = 0; i < N; i ++) { if (is_passive[i] && p[i] == -1) { dfs(i, adj, height, max_depth_node); roots_at_depth[height[i]].push_back(i); } } vi visited(N); for (int d = N - 1; d >= 0; d --) { while (D && !roots_at_depth[d].empty()) { int u = max_depth_node[roots_at_depth[d].back()]; roots_at_depth[d].pop_back(); while (u != -1) { for (auto x : adj[u]) { if (visited[x]) continue; p[x] = -1; roots_at_depth[height[x]].push_back(x); } visited[u] = 1; u = p[u]; } D --; } } ll sol = 0; for (int i = 0; i < N; i ++) { if (!is_passive[i] && t[i] <= T) sol ++; if (is_passive[i] && !visited[i]) sol ++; } cout << sol << '\n'; }
#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...