Submission #706649

#TimeUsernameProblemLanguageResultExecution timeMemory
706649ld_minh4354Cigle (COI21_cigle)C++17
100 / 100
251 ms392708 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back #define debug(x) cout<<#x<<": "<<x<<"\n" signed main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // freopen("input.000","r",stdin); // freopen("output.000","w",stdout); // srand((unsigned)time(NULL)); // rand() int n,i,a[5005],dp[5005][5005],j,cnt,l,diff,optl,ans,dpmax[5005][5005]; cin>>n; for (i=1;i<n+1;i++) cin>>a[i]; for (j=1;j<n+1;j++) dp[0][j]=dp[1][j]=0; for (j=1;j<n+1;j++) dpmax[0][j]=dpmax[1][j]=0; ans=0; for (i=2;i<n;i++) { cnt=0;l=i-1;diff=0;optl=i-1; dp[i][i+1]=dpmax[i-1][i]; dpmax[i][i+1]=max(dpmax[i-1][i+1],dp[i][i+1]); for (j=i+2;j<n+1;j++) { diff -= a[j-1]; while (diff<0 and l>0) { diff += a[l+1]; l--; } if (diff==0) { cnt++; optl=l; } dp[i][j]=max(dp[i][j-1],dpmax[optl][i]+cnt); dpmax[i][j]=max(dpmax[i-1][j],dp[i][j]); ans=max(ans,dp[i][j]); // cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<optl<<" "<<cnt<<"\n"; } } cout<<ans; }
#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...