이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
pair<long long,long long> dp[500005];
long long sum[500005],red[500005];
long long binary(long long now){
long long l=0,r=now,mid;
dp[now]={1000000000000007,0};
while(l<r){
mid=(l+r)/2;
long long s;
s=sum[mid];
if(sum[r]-s>=dp[mid].first)l=mid+1;
else r=mid;
//cout<<l<<"_"<<r<<endl;
}
return l;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin>>n;
cin>>red[0];
sum[0]=red[0];
for(int i=1;i<n;i++){
cin>>red[i];
sum[i]=sum[i-1]+red[i];
}
dp[0]={red[0],1};
for(int i=1;i<n;i++){
long long index=binary(i);
if(index==0){
if(sum[i]-red[0]>=red[0])dp[i]={sum[i]-red[i],2};
else dp[i]={sum[i],1};
}
else if (index<i)dp[i]={sum[i]-sum[index-1],dp[index-1].second+1};
else if (index==i && red[i]>=dp[i-1].first)dp[i]={red[i],dp[i-1].second+1};
else dp[i]={red[i]+dp[i-1].first,dp[i-1].second};
//cout<<index<<" - "<<i<<": "<<dp[i].first<<" "<<dp[i].second<<endl;
}
cout<<dp[n-1].second<<endl;
return 0;
}
# | 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... |