제출 #1160824

#제출 시각아이디문제언어결과실행 시간메모리
1160824mertbbmCigle (COI21_cigle)C++20
100 / 100
175 ms92456 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

void solve(){
	int n;
	cin >> n;
	int arr[n+5];
	for(int x=1;x<=n;x++){
		cin >> arr[x];
	}	
	
	int dp[n+5];
	memset(dp,0,sizeof(dp));
	vector<pii>storage[n+5];
	
	for(int x=1;x<=n;x++){
		//show(index,x);
		for(auto it:storage[x]){
			dp[it.first]=max(dp[it.first],it.second);
		}
		
		for(int y=1;y<=n;y++){
			dp[y]=max(dp[y],dp[y-1]);
		}
		
		int ptr=x+1;
		int counter=0;
		int counter2=0;
		int cnt=0;
		for(int y=x;y>=1;y--){
			counter+=arr[y];
			while(ptr<=n&&counter2<counter){
				counter2+=arr[ptr];
				ptr++;
			}
			
			if(counter==counter2){
				cnt++;
				//cout << ptr << " " << x << " " << dp[y-1]+cnt << "\n";
				if(y>=2)storage[ptr].push_back({x,dp[y-2]+cnt});
				//storage[ptr].push_back({x,dp[x-1]});
			}
		}
		//show4(dp,dp);
	}
	
	int best=0;
	for(int x=1;x<=n+1;x++) best=max(best,dp[x]);
	
	cout << best;
}
 
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("in.txt","w",stdout);
	int t=1;	
	//cin >> t;	
	while(t--){
		solve(); 
	}
}
#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...