제출 #420807

#제출 시각아이디문제언어결과실행 시간메모리
420807juancarlovieriCigle (COI21_cigle)C++17
100 / 100
444 ms134340 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 r = i; for (int j = 0; j <= r; ++j) { pref[r][j] = dp[j][r]; if (j) pref[r][j] = max(pref[r][j], pref[r][j - 1]); } } 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...