답안 #706626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706626 2023-03-07T08:24:42 Z ld_minh4354 Cigle (COI21_cigle) C++17
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"



signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("input.000","r",stdin);
//	freopen("output.000","w",stdout);
//	srand((unsigned)time(NULL));
//	rand()
	
	int n,i,a[5005],dp[5005][5005],j,cnt,l,diff,optl,ans,dpmax[5005];
	
	cin>>n;
	for (i=1;i<n+1;i++) cin>>a[i];
	
	for (j=1;j<n+1;j++) dp[0][j]=dp[1][j]=0;
	for (i=0;i<n+1;i++) dpmax[i]=0;
	
	ans=0;
	for (i=2;i<n;i++)
	{
		cnt=0;l=i-2;diff=a[i];optl=i-1;
		
		dp[i][i+1]=dpmax[i-1];
		dpmax[i+1]=max(dpmax[i+1],dp[i][i+1]);
		
		for (j=i+2;j<n+1;j++)
		{
			diff -= a[j-1];
			while (diff<0 and l>0)
			{
				diff += a[l+1];
				l--;
			}
			
			if (diff==0)
			{
				cnt++;
				optl=l;
			}
			dp[i][j]=cnt+dpmax[optl];
			ans=max(ans,dp[i][j]);
			dpmax[i]=max(dpmax[i],dp[i][j]);
//			cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<optl<<" "<<cnt<<"\n";
		}
	}
	
	cout<<ans;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -