Submission #1301788

#TimeUsernameProblemLanguageResultExecution timeMemory
1301788efegThe short shank; Redemption (BOI21_prison)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef pair<int,int> ii; using i64 = long long; template<typename T> using vec = vector<T>; template<typename T> void chmin(T &a,T b){ a = min(a,b); } int n,d,t; vec<vec<int>> adj; vec<bool> pasif,rem,vis; vec<int> a,depth,ptr; vec<ii> news; void dfs(int node){ if (vis[node]) return; vis[node] = true; int mxd = 0,idx = -1; for (auto x : adj[node]){ if (vis[x]) continue; dfs(x); if (depth[x] > mxd){ idx = x; mxd = depth[x]; } } ptr[node] = idx; depth[node] = mxd + 1; } void dfs2(int node){ rem[node] = true; for (auto x : adj[node]){ if (rem[x] || x == ptr[node]) continue; news.pb({depth[x],x}); } if (ptr[node] != -1) dfs2(ptr[node]); } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> d >> t; a.assign(n+1,0); adj.assign(n+1,vec<int>()); pasif.assign(n+1,0); depth.assign(n+1,0); ptr.assign(n+1,0); vis.assign(n+1,0); rem.assign(n+1,false); int minT = INT_MAX; for (int i=1; i <= n; i++){ cin >> a[i]; chmin(minT,a[i] - i); if (a[i] > t && minT <= t - i) pasif[i] = true; } stack<int> stk; for (int i = 1; i <= n; i++){ while (!stk.empty() && pasif[i]){ int tp = stk.top(); stk.pop(); if (pasif[tp]){ adj[i].pb(tp); stk.pop(); } else { if (a[tp] - tp <= t - i) break; } } stk.push(i); } priority_queue<ii,vec<ii>,greater<ii>> pq; for (int i = n; i > 0; i--){ if (!vis[i] && pasif[i]) { dfs(i); pq.push({depth[i],i}); } } int used = 0,engellendi = 0; while (!pq.empty() && used < d){ used++; int node,d;tie(d,node) = pq.top(); pq.pop(); engellendi += d; dfs2(node); for (auto pi : news){ pq.push(pi); } news.clear(); } cout << n - engellendi << endl; return 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...