数据
6
0 0 1 1 0 1
过不去(答案是6但是输出4),调不出来
by Lordi @ 2024-08-25 19:55:05
@[Lordi](/user/1400000)
试试这个
```cpp
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int n = 2E5+10;
int N, num, sumt, ans, na, nu, L[n], R[n];
signed main(){
scanf("%lld", &N);
memset(L, -1, sizeof(L));
memset(R, -1, sizeof(R));
L[N] = 0; // 初始化,因为 sumt 是从 N 开始的
for(int i = 1; i <= N; ++ i){
scanf("%lld", &num);
if(num) ++ na;
else ++ nu;
sumt = nu - na + N;
if(L[sumt] == -1) L[sumt] = i;
R[sumt] = i;
}
for(int i = 0; i <= N * 2; ++ i){
if(L[i] != -1 && R[i] != -1) ans = max(ans, R[i] - L[i]);
}
printf("%lld", ans);
return 0;
}
```
求关注!
by tanjunhan666 @ 2024-08-25 20:02:29