# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1077014 | lucri | Tortoise (CEOI21_tortoise) | C++17 | 0 ms | 344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
long long cost,n,v[10010],l[10010],r[10010],jump[10010],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 poz=1,time=0,zid=-10010;
if(candy(0,1)==false)
return false;
time=r[1]-1;
for(int i=1;i<=n;++i)
{
if(v[i]==-1)
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()
{
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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |