Submission #707161

# Submission time Handle Problem Language Result Execution time Memory
707161 2023-03-08T14:25:29 Z emptypringlescan Cigle (COI21_cigle) C++17
0 / 100
3 ms 2260 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	long long arr[n],dp[n][n];
	for(int i=0; i<n; i++) cin >> arr[i];
	memset(dp,0,sizeof(dp));
	long long ans=0;
	for(int i=1; i<n; i++){
		long long pref[n],score[n];
		pref[0]=dp[0][i-1];
		for(int j=1; j<i; j++) pref[j]=min(pref[j-1],dp[j][i-1]);
		int c=i-1,be=0;
		long long len=0,len2=0;
		for(int j=i; j<n; j++){
			len+=arr[j];
			while(len2<len&&c>=0){
				len2+=arr[c];
				c--;
			}
			if(c>0) dp[i][j]=pref[c-1]+be;
			if(len2==len) be++;
		}
		c=i;
		len=0; len2=0;
		score[i]=0;
		for(int j=i-1; j>=0; j--){
			len+=arr[j];
			while(len2<len&&c<n){
				len2+=arr[c];
				c++;
			}
			if(len==len2) score[j]=score[j+1]+1;
			else score[j]=score[j+1];
		}
		long long best=0;
		len=0; len2=0; c=i-1; be=0;
		for(int j=i; j<n; j++){
			len+=arr[j];
			while(len2<len&&c>=0){
				len2+=arr[c];
				best=max(best,dp[c][i-1]+be);
				c--;
			}
			if(len==len2) be++;
			dp[i][j]=max(dp[i][j],best);
			ans=max(ans,dp[i][j]);
		}
	}/*
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++) cout << dp[i][j] << ' ';
		cout << '\n';
	}*/
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2260 KB Output is correct
2 Incorrect 3 ms 2236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -