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>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = int;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
int main() {
ll N;
cin >> N;
vector<ll> A(N);
rep(i,N) cin >> A[i];
vector<vector<ll>> ep(N,vector<ll>(N,0));
rep(i,N){
for(ll j=i;j<N;j++){
set<ll> s;
ll cnt_l=0;
for(ll k=j;k>i;k--){
cnt_l+=A[k];
s.insert(cnt_l);
}
ll cnt=0;
ll cnt_r=0;
for(ll k=j+1;k<N;k++){
ep[j+1][k]=max(ep[j+1][k],ep[i][j]+cnt);
cnt++;
cnt_r+=A[k];
if(s.find(cnt_r)==s.end()) cnt--;
}
}
}
ll ans=0;
rep(i,N) ans=max(ans,ep[i][N-1]);
cout << ans << 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... |