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;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define ll long long
#define fi first
#define se second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nax=5e5+5;
signed main(){
iostream::sync_with_stdio(false);
int n;
cin>>n;
int tab[n];
for (int i = 0; i < n; ++i)
{
cin>>tab[i];
}
int dp[n][n];
memset(dp,0,sizeof dp);
for (int i = 0; i < n; ++i)
{
for (int j = i; j < n; ++j)
{
int cnt=0;
int cur=i;
int a=0;
int b=0;
//cout <<i<<" "<<j<<endl;
for (int k = i-1; k >= 0 ; --k)
{
a+=tab[k];
while(cur<=j&&b<a){
b+=tab[cur++];
}
//cout <<k<<" "<<a<<" "<<b<<" "<<cur<<" "<<dp[k][i-1]<<endl;
dp[i][j]=max(dp[i][j],dp[k][i-1]+cnt);
if(a==b&&k>0&&cur<=j) cnt++;
}
}
}
int ans=0;
for (int i = 0; i < n; ++i)
{
//cout <<dp[i][n-1]<<endl;
ans=max(ans,dp[i][n-1]);
}cout <<ans<<endl;
}
# | 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... |