Submission #1123178

#TimeUsernameProblemLanguageResultExecution timeMemory
1123178razivoThe short shank; Redemption (BOI21_prison)C++20
0 / 100
160 ms8668 KiB
#include <iostream> #include <queue> #include <vector> #include <tuple> using namespace std; vector<int> v(2e6); pair<pair<int,int>,int> opt(int i, int j) { int best = 0; int bestpos = j-1; vector<int> q; for (int k = j-1; k >=i; --k) { if(v[k]==-1) { q.push_back(k); continue; } int p = k+v[k]; int v = 0; while(!q.empty() && q.back()<p) { q.pop_back(); v++; } if(v>best) { best=v; bestpos=k; } } return {{q.size(),best},bestpos}; } int main() { int n,d,t; cin>>n>>d>>t; for (int i = 0; i < n; ++i) { int x; cin>>x; if(x>t) v[i]=-1; else v[i]=t-x+1; } priority_queue<pair<int,tuple<int,int,int>>> q; auto [a,b] = opt(0,n); auto [l,m] = a; int init = n-l; q.push({m,{b,0,n}}); for (int i = 0; i < d; ++i) { auto [a,b] = q.top(); q.pop(); auto [p,l,r] = b; init-=a; auto [u,v] = opt(l,p+1); auto [u2,v2] = opt(p+1,r); q.push({u.second,{v,l,p+1}}); q.push({u2.second,{v2,p+1,r}}); } cout<<init<<endl; }
#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...