更快了
```
#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 >= 3e8 + 50000000) 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;
}
```
by BK小鹿 @ 2024-10-29 22:49:16