Untitled

 avatar
unknown
plain_text
5 months ago
898 B
3
Indexable
// ThonqRiu
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 1000005
#define MOD 100000000000007
#define Task "bai1"
#define ll long long
using namespace std;
ll a[maxn],n,r,res,d;
bool check(int l, int r){
    unordered_set<ll> s;
    for(int i = 1; i<=n; i++)
        if(i < l || i > r){
            if(s.find(a[i]) != s.end()) return 0;
            s.insert(a[i]);
        }
    return 1;
}
int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(nullptr);
    if(fopen(Task".inp","r")){
        freopen(Task".inp","r",stdin);
    }
    cin >> n;
    for(int i = 1; i<=n; i++)
        cin >> a[i];
    if(check(0,0)){
        cout << n;
        return 0;
    }
    int r = 2;
        for(int l = 1; l<=n; l++){
            while(!check(l,r) && r <= n) r++;
            if(check(l,r)) res = max(res,n - (r - l + 1));
        }
    cout << res;
}
Editor is loading...
Leave a Comment