Submission #420488

#TimeUsernameProblemLanguageResultExecution timeMemory
420488BertedCigle (COI21_cigle)C++14
48 / 100
1055 ms108120 KiB
#include <iostream> using namespace std; int N, A[5001]; int cst[5001][5001], DP[5001][5001]; int main() { cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) { int sumL = 0, sumR = 0, l = i - 1, r = i; while (l >= 0 && r < N) { if (sumL + A[l] < sumR + A[r]) {sumL += A[l--];} else {sumR += A[r++];} if (l >= 0 && r < N && sumL == sumR) {cst[i][l] = 1; cst[i][r] = 1;} } for (int j = i + 1; j < N; j++) cst[i][j] = cst[i][j - 1] + cst[i][j]; for (int j = i - 2; j >= 0; j--) cst[i][j] = cst[i][j + 1] + cst[i][j]; } for (int i = 0; i < N; i++) { for (int j = 0; j <= i; j++) { //cerr << i << " " << j << " DP\n"; for (int k = j - 1; k >= 0; k--) { DP[i][j] = max(DP[i][j], DP[j - 1][k] + min(cst[j][i], cst[j][k])); //cerr << j - 1 << " " << k << " " << DP[j - 1][k] << " " << min(cst[j][i], cst[j][k]) << "\n"; } //cerr << "DPF: " << i << " " << j << " " << DP[i][j] << "\n"; } } int res = 0; for (int i = 0; i < N; i++) {res = max(res, DP[N - 1][i]);} cout << res << "\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...