Submission #524157

#TimeUsernameProblemLanguageResultExecution timeMemory
524157inluminasBigger segments (IZhO19_segments)C++17
13 / 100
1 ms332 KiB
#include"bits/stdc++.h" using namespace std; #define ll long long #define endl "\n" #define fastio ios_base::sync_with_stdio(false) #define inf LLONG_MAX int main(){ fastio; int n; cin>>n; ll pre[n+1],dp[n+1],ans[n+1]; pre[0]=0; for(int i=1;i<=n;i++){ ll x; cin>>x; pre[i]=pre[i-1]+x; dp[i]=ans[i]=0; } dp[0]=ans[0]=0; for(int i=1;i<=n;i++){ int lo=0,hi=i-1; while(hi-lo>1){ int mid=(lo+hi)>>1; if(pre[i]-pre[mid]>=dp[mid]) lo=mid; else hi=mid; } if(pre[i]-pre[hi]>=dp[hi]){ dp[i]=pre[i]-pre[hi]; ans[i]=ans[hi]+1; }else if(pre[i]-pre[lo]>=dp[lo]){ dp[i]=pre[i]-pre[lo]; ans[i]=ans[lo]+1; }else{ dp[i]=pre[i]; ans[i]=1; } } cout<<ans[n]<<endl; 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...