Submission #420751

#TimeUsernameProblemLanguageResultExecution timeMemory
420751juancarlovieriCigle (COI21_cigle)C++17
0 / 100
5 ms5292 KiB
#include <bits/stdc++.h> using namespace std; int dp[5005][5005]; int pref[5005][5005]; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; ++i) cin >> arr[i]; for (int i = 1; i < n; ++i) { int cur = 0, prev = 0, v = 0; int i2 = i; for (int j = i; j < n; ++j) { cur += arr[j]; while (i2 && prev < cur - arr[j]) { --i2; prev += arr[i2]; } if (i2 && prev == cur - arr[j]) { if (prev) ++v; --i2; prev += arr[i2]; } dp[i][j] = pref[i - 1][i2] + v; if (i != j) dp[i][j] = max(dp[i][j], dp[i][j - 1]); pref[j][i] = max(pref[j][i], dp[i][j]); } } int ans = 0; for (int i = 0; i < n; ++i) ans = max(ans, dp[i][n - 1]); cout << ans << endl; }
#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...