Submission #681770

#TimeUsernameProblemLanguageResultExecution timeMemory
681770Cross_RatioCigle (COI21_cigle)C++14
100 / 100
258 ms67396 KiB
#include <bits/stdc++.h> using namespace std; int A[5005]; int B[5005][5005]; int C[5005]; signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; int i, j; for(i=0;i<N;i++) cin >> A[i]; //A[0][0] = A[0][1] = .. = A[0][N+1] = 0 for(j=1;j<N;j++) { for(i=0;i<=j-1;i++) C[i] = B[i][j]; for(i=0;i+1<=j-1;i++) C[i+1] = max(C[i+1], C[i]); int val = C[j-1]; int pt = j; int cnt = 0; int sum1 = 0, sum2 = 0; for(int k=j+1;k<N+1;k++) { if(k >= j+2) sum1 += A[k-2]; while(sum2 < sum1 && pt-1>=0) { sum2 += A[pt-1]; pt--; } if(k>=j+2&&sum1==sum2) { cnt++; } //cout << j << ", " << k << " : " << sum1 << ' '<< sum2 << ' ' << pt << ' ' << cnt << '\n'; if(pt>=1) val = max(val, cnt + C[pt-1]); B[j][k] = max(B[j][k], val); } } int ans = 0; for(i=0;i<N;i++) ans = max(ans, B[i][N]); cout << ans; }
#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...