Submission #1077019

#TimeUsernameProblemLanguageResultExecution timeMemory
1077019lucriTortoise (CEOI21_tortoise)C++17
73 / 100
125 ms744 KiB
#include <bits/stdc++.h> using namespace std; long long cost,n,v[10020],l[10020],r[10020],jump[10020],nr; priority_queue<pair<int,int>>q; bool candy(int time,int poz) { bool ok=false; for(int i=poz;v[i]!=-1;++i) if(v[i]||jump[i]) ok=true; if(ok==false) return true; for(int i=poz;v[i]!=-1;++i) if(v[i]&&time+i-poz<=(i-1)*2) return true; return false; } bool ok() { int time=0; if(candy(0,1)==false) return false; time=r[1]-1; for(int i=1;i<=n;++i) { if(v[i]==-1) { if(v[i-1]==-1) ++time; continue; } if(r[i]-i==i-l[i]||r[i]-i==(i-1)-l[i]) { if(candy(time-(i-1-l[i])+1,l[i]+1)==false) return false; time+=r[i]-(i-1); } if(r[i]-i<=i-l[i]) { for(int j=1;j<=jump[i];++j) { if(time+r[i]-i>2*(i-1)) return false; time+=2*(r[i]-i); } } else { ++time; for(int j=1;j<=jump[i];++j) { if(time>2*(i-1)) return false; time+=2*(i-l[i]); } } } if(candy(time-(n-l[n])+1,l[n]+1)==false) return false; return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; for(int i=1;i<=n;++i) cin>>v[i]; v[10010]=-1; l[0]=-10010; r[n+1]=10010; for(int i=1;i<=n;++i) { l[i]=l[i-1]; if(v[i]==-1) l[i]=i; } for(int i=n;i>=1;--i) { r[i]=r[i+1]; if(v[i]==-1) r[i]=i; } for(int i=1;i<=n;++i) q.push({-min(r[i]-i,i-l[i]),i}); while(!q.empty()) { int ind=q.top().second; q.pop(); if(v[ind]==-1) continue; while(v[ind]) { --v[ind]; ++jump[ind]; if(ok()==false) { ++v[ind]; --jump[ind]; break; } } } for(int i=1;i<=10010;++i) if(v[i]!=-1) nr+=v[i]; else { if(nr) --cost; nr=0; } for(int i=1;i<=n;++i) if(v[i]!=-1) cost+=v[i]; cout<<cost; 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...