Submission #535669

#TimeUsernameProblemLanguageResultExecution timeMemory
535669MOUF_MAHMALATCigle (COI21_cigle)C++14
48 / 100
1082 ms1452 KiB
#include<bits/stdc++.h> #define all(s) s.begin(),s.end() #define F first #define S second using namespace std; typedef int ll; ll n,a[5009],dp[509][509],p[5009],ans; int main() { ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n; for(ll i=1; i<=n; i++) { cin>>a[i]; p[i]=p[i-1]+a[i]; } for(ll i=2; i<=n; i++) { for(ll j=i; j<=n; j++) { ll sum=0,l=i; dp[i][j]=dp[i-1][i-1]; for(ll k=i-2; k; k--) { if(i==j) { dp[i][j]=max(dp[i][j],dp[k][i-1]); continue; } while((p[l]-p[i-1]<p[i-1]-p[k])&&(l<j-1)) l++; if(p[l]-p[i-1]==p[i-1]-p[k]) sum++; dp[i][j]=max(dp[i][j],dp[k][i-1]+sum); } } } for(ll i=1; i<=n; i++) ans=max(ans,dp[i][n]); cout<<ans; 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...