제출 #487509

#제출 시각아이디문제언어결과실행 시간메모리
487509ETKCigle (COI21_cigle)C++14
0 / 100
5 ms7760 KiB
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) #define pii pair<int,int> #define vi vector<int> #define fi first #define se second #define pb push_back #define ALL(x) x.begin(),x.end() #define ll long long using namespace std; inline ll read(){ ll x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();} while (isdigit(ch)){x=x*10+ch-48;ch=getchar();} return x*f; } const int N=5e3+5; int a[N],dp[N][N],g[N][N],pos[N][N]; void Max(int &a,const int b){if(a<b)a=b;} int main(){ int n=read(); rep(i,1,n)a[i]=read(); rep(i,1,n){ int sum=0,pre=0,p=i-1; rep(j,i,n){ dp[i][j]=dp[i-1][i-1]; g[i][j]=g[i][j-1]; sum+=a[j]; while(p&&pre+a[p]<=sum)pre+=a[p--]; if(sum==pre)g[i][j]++; pos[i][j]=p; if(pos[i][j-1])Max(dp[i][j-1],dp[pos[i][j-1]][i-1]+g[i][j-1]); Max(dp[i][j],dp[i][j-1]); Max(dp[i][j],dp[i-1][j]); } } printf("%d\n",dp[n][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...