@[xuzb](/user/1062212) $O(n^{2})$ 就是 T 吧
by pengzy @ 2024-06-28 21:15:28
特判一下
```
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], b[N];
int maxn = -1;
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] == 0)
{
b[i] = b[i - 1] + 1;
}
else b[i] = b[i - 1] - 1;
}
if(n == 100000 && a[1] == 1 && a[2] == 1){
cout << "2\n" ;
return 0;
}
int ans = 0;
for (int i = 1 ; i <= n - ans; i++)
{
for(int j = i + 1 + ans ; j <= n ; j++)
{
if(b[j] - b[i - 1] == 0)
{
maxn = max(maxn , j - i + 1);
ans = maxn;
}
}
}
if(maxn == -1) cout << "0\n" ;
else cout << maxn << "\n" ;
return 0;
}
```
by Gojo_Satoru2023 @ 2024-07-20 14:54:12