Submission #1033489

#TimeUsernameProblemLanguageResultExecution timeMemory
1033489tvladm2009Cigle (COI21_cigle)C++17
0 / 100
3 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define sz(a) a.size() typedef long long ll; const int N = 5e3 + 7; int a[N]; int dp[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { int cnt = 0; int cur = i; int sa = 0; int sb = 0; for (int k = i - 1; k >= 0; k++) { sa += a[k]; while (cur <= j && sb < sa) { sb += a[cur]; cur++; } dp[i][j] = max(dp[i][j], dp[k][i - 1] + cnt); if (sa == sb && cur <= j) cnt++; } } } int ans = 0; for (int i = 0; i < n; i++) ans = max(ans, dp[i][n - 1]); cout << ans << "\n"; 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...