求助70pts
查看原帖
求助70pts
186749
Quan_200605楼主2020/6/12 17:22

rt

70pts

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll max(ll a,int b){return a>b?a:b;}
const int maxn=5e5+10;
int n;
ll f[maxn],tot[maxn];
ll sum,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>f[i];
		if(f[i]==0)f[i]=-1;
	}
	for(int i=1;i<=n;i++){
		sum+=f[i];
		if(!tot[sum+n])tot[sum+n]=i;
		else ans=max(i-(tot[sum+n]+1)+1,ans);
	}
	printf("%lld\n",ans);
	return 0;
}
/*
9
0 1 0 0 0 1 1 0 0
*/
2020/6/12 17:22
加载中...