Submission #420706

#TimeUsernameProblemLanguageResultExecution timeMemory
420706rama_pangCigle (COI21_cigle)C++17
100 / 100
324 ms98400 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<vector<int>> dp(N, vector<int>(N)); for (int mid = N - 1; mid >= 1; mid--) { for (int i = N - 1; i >= mid; i--) { if (i + 1 < N) { dp[mid][i] = max(dp[mid][i], dp[mid][i + 1]); } if (mid + 1 < N) { dp[mid][i] = max(dp[mid][i], dp[mid + 1][i]); } } // [mid - 1, mid] as splitting point int sumLft = 0; int sumRgt = 0; int cost = 0; int ptr = mid; for (int i = mid - 1; i >= 0; i--) { sumLft += A[i]; while (ptr < N && sumRgt < sumLft) { sumRgt += A[ptr]; ptr += 1; } cost += (sumLft == sumRgt); if (i > 0 && ptr < N) { dp[i - 1][mid - 1] = max(dp[i - 1][mid - 1], dp[mid][ptr] + cost); } } } int ans = 0; for (int i = 0; i < N; i++) { ans = max(ans, dp[0][i]); } 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...