Submission #543848

#TimeUsernameProblemLanguageResultExecution timeMemory
543848levladiatorCigle (COI21_cigle)C++14
0 / 100
119 ms1404 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front #define ll long long #define ull unsigned long long #define pii pair<int,int> #define pll pair<ll,ll> #define EPSILON 0.000001 #define CH (*s-'a') using namespace std; const ll NMAX = 5e2 + 5, INF = 1e18, MOD = 1e9 + 7, MMAX = 1e2 + 5, inf = 1e9; ifstream fin("sufle.in"); ofstream fout("sufle.out"); int N,ans; int v[NMAX],best[NMAX][NMAX],S[NMAX]; int main() { cin.tie ( 0 )->sync_with_stdio ( 0 ); cin.tie ( NULL ); cout.tie ( NULL ); cin>>N; for(int i=1;i<=N;i++) { cin>>v[i]; S[i]=S[i-1]+v[i]; } for(int i=2;i<=N;i++) { for(int j=i;j>=1;j--) { int ind=j-1; int layer=0; int sum=0; for(int k=j;k<=i;k++) { sum+=v[k]; while(sum>layer&&ind>0) { layer+=v[ind]; ind--; } if(sum==layer&&k<i)best[i][j]++; } ind++; if(layer>sum) { if(sum-v[i]<layer-v[ind+1]) { ind++; layer-=v[ind]; } } else if(layer<sum) { if(sum-v[i]>=layer) { if(j>1)best[i][j]=-1; } } int add=0; for(int k=ind;k>=1;k--) { add=max(add,best[j-1][k]); } best[i][j]+=add; ans=max(ans,best[i][j]); } } cout<<ans; 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...