Submission #1102783

#TimeUsernameProblemLanguageResultExecution timeMemory
1102783epicci23The short shank; Redemption (BOI21_prison)C++17
100 / 100
303 ms174784 KiB
#include "bits/stdc++.h" //#define int long long #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() using namespace std; const int N = 2e6 + 5; const int INF = 1e9; const int LOG = 20; int n,d,t; vector<vector<int>> v; vector<int> ar,par,mark,vis,dp,ptr; void dfs(int c){ if(vis[c]) return; vis[c]=1; ptr[c]=c; dp[c]=0; for(int x:v[c]){ dfs(x); if(dp[x]>=dp[c]){ dp[c]=dp[x]+1; ptr[c]=ptr[x]; } } } void _(){ cin >> n >> d >> t; v.resize(n+5),ar.resize(n+5),par.assign(n+5,-1); mark.assign(n+5,0),vis.assign(n+5,0); dp.resize(n+5);ptr.resize(n+5); for(int i=1;i<=n;i++) cin >> ar[i]; stack<int> s,s2; int hm = INF,lol=0; for(int i=1;i<=n;i++){ hm++; hm=min(hm,ar[i]); if(hm<=t && ar[i]>t){ mark[i]=1; while(!s2.empty() && ar[s2.top()]+i-s2.top()>t) s2.pop(); while(!s.empty() && s.top()+t-ar[s.top()]<i && (s2.empty() ? 0 : s2.top())<s.top()){ par[s.top()]=i; v[i].push_back(s.top()); s.pop(); } s.push(i); } else s2.push(i); } priority_queue<array<int,2>> pq; vector<int> use(n+5,0),kill(n+5,0); for(int i=1;i<=n;i++){ if(!mark[i]) continue; dfs(i); if(par[i]==-1) pq.push({dp[i],i}); } while(d-- && !pq.empty()){ int c = pq.top()[1]; pq.pop(); use[ptr[c]]=1; int u=ptr[c]; while(u!=c){ kill[u]=1; for(int x:v[u]) if(!kill[x]) pq.push({dp[x],x}); u=par[u]; } for(int x:v[u]) if(!kill[x]) pq.push({dp[x],x}); } int ans=0;hm=INF; for(int i=1;i<=n;i++){ hm++; if(use[i]) hm=ar[i]; else hm=min(hm,ar[i]); if(hm<=t) ans++; } cout << ans << '\n'; } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int tc=1;//cin >> tc; while(tc--) _(); return 0; }

Compilation message (stderr)

prison.cpp: In function 'void _()':
prison.cpp:36:16: warning: unused variable 'lol' [-Wunused-variable]
   36 |   int hm = INF,lol=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...