比赛 20241024 评测结果 AAAAA
题目名称 “非常男女”计划 最终得分 100
用户昵称 darkMoon 运行时间 0.062 s
代码语言 C++ 内存使用 5.56 MiB
提交时间 2024-10-24 07:47:12
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
using namespace std;
auto IN = freopen("teen.in", "r", stdin);
auto OUT = freopen("teen.out", "w", stdout);
auto mread = [](){int x;scanf("%lld", &x);return x;};
const int N = 1e5 + 5;
int n = mread(), a[N], s[N], fi[N + N];
signed main(){
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        if(a[i] == 0){
            a[i] = -1;
        }
        s[i] = s[i - 1] + a[i];
    }
    memset(fi, -1, sizeof(fi));
    fi[0 + N] = 0;
    int ans = 0;
    for(int i = 1; i <= n; i ++){
        if(fi[s[i] + N] == -1){
            fi[s[i] + N] = i;
        }
        else{
            ans = max(ans, i - fi[s[i] + N]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}