Submission #1002714

#TimeUsernameProblemLanguageResultExecution timeMemory
1002714SofiatpcCigle (COI21_cigle)C++14
48 / 100
993 ms2632 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; int dp[MAXN][MAXN], dp1[MAXN][MAXN], d[MAXN], sp[MAXN]; int sum(int i, int j){ return sp[j] - sp[i-1]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i = 1; i <= n; i++){ cin>>d[i]; sp[i] = sp[i-1]+d[i]; } int ans = 0; for(int l = n-1; l >= 1; l--) for(int r = n-1; r >= l; r--){ set<int> st; for(int i = l; i < r; i++)st.insert(sum(i+1,r)); //cout<<l<<" "<<r<<": "; //for(int x : st)cout<<x<<" "; cout<<" | "; int qtd = 0; for(int j = r+1; j < n; j++) if(st.find(sum(r+1,j)) != st.end()){ qtd++; dp[l][r] = max(dp[l][r], dp1[r+1][j+1]+qtd); } //cout<<dp[l][r]<<" "<<qtd<<"\n"; ans = max(ans,dp[l][r]); dp1[l][r] = max(dp1[l][r+1],dp[l][r]); } cout<<ans<<"\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...