Submission #420836

#TimeUsernameProblemLanguageResultExecution timeMemory
420836HappyPacManCigle (COI21_cigle)C++14
0 / 100
3 ms2764 KiB
#include <bits/stdc++.h> using namespace std; const int MXN = 5005; int dp[MXN][MXN]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; int arr[N]; for(int i=0;i<N;i++) cin >> arr[i]; int res = 0; for(int i=1;i<N;i++){ int pref[i]; pref[0] = dp[0][i-1]; for(int j=1;j<i;j++) pref[j] = max(pref[j-1],dp[j][i-1]); int l=0,r=0,lst=i-1,cost=0; for(int j=i,k=i-1;j<N;j++){ dp[i][j] = pref[lst] + cost; l += arr[j]; if(k >= 0 && r+arr[k] <= l) r += arr[k--]; if(l == r && k >= 0){ cost++,lst=k; r += arr[k--]; } } for(int j=i+1;j<N;j++) dp[i][j] = max(dp[i][j-1],dp[i][j]); for(int j=0;j<N;j++) res = max(res,dp[i][j]); } cout << res << '\n'; }
#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...