Submission #1277991

#TimeUsernameProblemLanguageResultExecution timeMemory
1277991namhhCigle (COI21_cigle)C++20
0 / 100
4 ms5192 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define fi first #define se second const int N = 5e3+5; int n,a[N],dp[N][N],pre[N][N]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 2; i <= n; i++){ int l = i-1; int cur1 = 0; int cur2 = 0; int cnt = -1; bool ck = true; for(int j = i; j <= n; j++){ while(cur2 <= cur1){ if(cur2 == cur1) cnt++; if(l == 0){ ck = false; break; } cur2 += a[l]; l--; } if(ck == false) break; dp[i][j] = pre[i-1][l+1]+cnt; cur1 += a[j]; } for(int j = 1; j <= i; j++) pre[i][j] = max(pre[i][j-1],dp[j][i]); } int ans = 0; for(int i = 1; i <= n; i++) ans = max(ans,dp[i][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...