请求加强数据
查看原帖
请求加强数据
1345783
BK小鹿楼主2024/10/29 22:46

rt,n^2过了,加了个神秘特判

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
int a[N], sum[N], ans;
int main(){
	int cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i ++ ) cin >> a[i], sum[i] += sum[i - 1] + a[i];
	for (int end = n; end >= 1; end -- ){
		if (end - 1 <= ans) break;
		if (cnt >= 1e9) break;
		bool fl = 0;
		int S;
		for (int St = 1; St < end; St ++ ){
			if (end - St + 1 <= ans) break;
			cnt ++ ;
			int boy = sum[end] - sum[St - 1], girl = end - St + 1 - boy;
			if (boy == girl){
				fl = 1;
				S = St;
				break;
			}
		}
		if (fl){
			ans = max(ans, end - S + 1);
		}
	}
	cout << ans;
	return 0;
}
2024/10/29 22:46
加载中...