# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
711218 | ToroTN | Bigger segments (IZhO19_segments) | C++14 | 1 ms | 340 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;
#define X first
#define Y second
#define ll long long
ll n,a[500005],qs[500005],dp[500005],sum[500005],st,md,ed;
ll query(ll l,ll r)
{
if(l>r)return 0;
return qs[r]-qs[l-1];
}
int main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
qs[i]=qs[i-1]+a[i];
}
dp[0]=0,sum[0]=0;
for(int i=1;i<=n;i++)
{
dp[i]=1e18,sum[i]=1e18;
}
for(int i=1;i<=n;i++)
{
st=0;
ed=i-1;
while(ed>=st)
{
md=(st+ed)/2;
if(query(md+1,i)>=sum[md])
{
st=md+1;
}else
{
ed=md-1;
}
}
dp[i]=dp[ed]+1;
sum[i]=query(ed+1,i);
}
//printf("%lld %lld\n",dp[n],sum[n]);
printf("%lld\n",dp[n]);
}
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... |