Submission #173040

#TimeUsernameProblemLanguageResultExecution timeMemory
173040LinusTorvaldsFanBigger segments (IZhO19_segments)C++14
0 / 100
2 ms504 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector<int>a(n); for(int i=0;i<n;i++)cin>>a[i]; vector<ll>pr(n+1); for(int i=0;i<n;i++)pr[i+1]=pr[i]+a[i]; vector<int>ans(n); vector<ll> ans_sum(n); ll sum=0; for(int i=0;i<n;i++){ sum+=a[i]; ans_sum[i]=sum; ans[i]=1; } for(int i=1;i<n;i++){ for(int j=i-1;j>=0;j--){ if(pr[i+1]>=ans_sum[j]+pr[j+1]){ ans[i]=ans[j]+1; ans_sum[i]=pr[i+1]-pr[j+1]; break; } } } for(int i=0;i<n-1;i++){ assert(ans_sum[i]<=ans_sum[i+1]); } cout<<ans[n-1]; 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...