Submission #586070

#TimeUsernameProblemLanguageResultExecution timeMemory
586070MilosMilutinovicCigle (COI21_cigle)C++14
48 / 100
1085 ms98692 KiB
/** * author: wxhtzdy * created: 29.06.2022 21:43:16 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> pref(n + 1); for (int i = 0; i < n; i++) { pref[i + 1] = pref[i] + a[i]; } vector<vector<int>> dp(n + 1, vector<int>(n + 1)); for (int l = 1; l <= n; l++) { map<long long, int> cnt; for (int r = l; r <= n; r++) { int ft = 0; for (int i = l - 1; i >= 1; i--) { dp[l][r] = max(dp[l][r], dp[i][l - 1] + ft); if (cnt.count(pref[l - 1] - pref[i - 1])) { ft += 1; } } cnt[pref[r] - pref[l - 1]]++; } } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, dp[i][n]); } 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...