제출 #1190913

#제출 시각아이디문제언어결과실행 시간메모리
1190913DanielPr8The short shank; Redemption (BOI21_prison)C++20
0 / 100
1 ms320 KiB
#include <bits/stdc++.h> using namespace std; using ll = int; using vll = vector<ll>; using vvl = vector<vll>; using pll = pair<ll,ll>; using vpl = vector<pll>; using vvp = vector<vpl>; #define f first #define s second #define pb push_back #define all(v) v.begin(),v.end() vvl g; vll vis, dep, bes, pr; void dfs(ll cur){ bes[cur]=cur; for(ll i:g[cur]){ dep[i]=dep[cur]+1; pr[i]=cur; dfs(i); if(dep[bes[i]]>dep[bes[cur]])bes[cur]=bes[i]; } } ll m = 0; void ear(priority_queue<pll>& pq, ll i){ if(vis[i]==1)return; m++; vis[i]=1; for(ll j:g[i]){ if(!vis[j]){ pq.push({dep[bes[j]]-dep[j],j}); } } if(pr[i]!=-1)ear(pq, pr[i]); } int main(){ ios_base::sync_with_stdio(0);cin.tie(NULL); ll n, d, t; cin >> n >> d >> t; vll tm(n), ls(n); stack<pll> w; w.push({-1e9, -1}); for(ll i = 0; i < n; ++i){ cin >> tm[i]; w.push({tm[i], i}); while(w.top().f+i-w.top().s>t){ w.pop(); } ls[i]=w.top().s; if(ls[i]==-1)m++; } pr = vll(n,-1); stack<pll> q; g = vvl(n); vis=dep=bes=vll(n); vll lon; priority_queue<pll> pq; for(ll i = n-1; i >= 0; --i){ if(ls[i]==i || ls[i]==-1)continue; if(!q.empty()){ while(q.top().f>=i){ q.pop(); } } if(q.empty()){lon.pb(i);q.push({ls[i], i});continue;} g[q.top().s].pb(i); q.push({ls[i], i}); } for(ll i: lon){ dfs(i); pq.push({dep[bes[i]], i}); } while(d-- && !pq.empty()){ auto [a,b] = pq.top(); pq.pop(); ear(pq, bes[b]); } cout << n-m; }
#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...