Submission #1116180

# Submission time Handle Problem Language Result Execution time Memory
1116180 2024-11-21T10:08:29 Z NotLinux Cigle (COI21_cigle) C++17
0 / 100
6 ms 6224 KB
// Author : FatihCihan
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
const int N = 1e3 * 1e3 + 7;
const int inf = 1e9 + 7;
void solve(){
	int n;
	cin >> n;
	int arr[n] , pre[n+1] , cnt[N];
	memset(cnt , -1 , sizeof(cnt));
	pre[0] = 0;
	cnt[0] = -1;
	for(int i = 0;i<n;i++){
		cin >> arr[i];
		pre[i+1] = pre[i] + arr[i];
		cnt[pre[i+1]] = i;
	}
	int dp[n+1][n+1] = {0} , maxi[n+1][n+1] = {0};
	for(int j = 2;j<n;j++){
		int sayac = 0;
		for(int i = j+1;i<=n;i++){
			if(2 * pre[j] - pre[i] >= 0 and cnt[2 * pre[j] - pre[i]] != -1){
				sayac++;
				// cout << " aha : " << i << " , " << j << " => " << sayac << " + " << maxi[j-1][cnt[2 * pre[j] - pre[i]]] << endl;
				dp[i+1][j] = max(dp[i+1][j] , maxi[j-1][cnt[2 * pre[j] - pre[i]]] + sayac);
				// cout << "AHA : " << i << " , " << j << " : " << maxi[j-1][cnt[2 * pre[j] - pre[i]]] << " tf " << cnt[2 * pre[j] - pre[i]] << endl;
			}
			else{
				dp[i+1][j] = max(dp[i+1][j] , dp[i][j]);	
			}
			maxi[i][j] = max(maxi[i][j-1] , dp[i][j]);
			if(j > 0){
				if(i - j > 1)dp[i+1][i] = max(dp[i+1][i] , dp[i][j]);	
			}
			else{
				if(i > 2)dp[i+1][i] = max(dp[i+1][i] , dp[i][j]);	
			}
			// cout << i << " " << j << " : " << dp[i][j] << endl;
		}
	}
	int ans = 0;
	for(int i = 0;i<n;i++){
		ans = max(ans , dp[n][i]);
	}
	cout << ans << endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
	cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 6224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4176 KB Output isn't correct
2 Halted 0 ms 0 KB -