-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
58 lines (57 loc) · 1.01 KB
/
B.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
long long n,i,ara[2005],cur=0,mx=0,j,pr=0,sf=0;
map<long long, long long> mp;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>ara[i];
}
for(i=1;i<=n;i++)
{
if(mp[ara[i]]==0)
{
pr++;
mp[ara[i]]=i;
}
else
break;
}
mp.clear();
for(i=n;i>=1;i--)
{
if(mp[ara[i]]==0)
{
sf++;
mp[ara[i]]=i;
}
else
break;
}
mx=max(pr,sf);
for(i=1;i<=pr;i++)
{
mp.clear();
cur=min(i,pr);
for(j=1;j<=i;j++)
mp[ara[j]]=j;
for(j=n;j>i;j--)
{
if(mp[ara[j]]==0)
{
cur++;
mp[ara[j]]=j;
}
else
break;
}
mx=max(mx,cur);
}
cout<<n-mx<<"\n";
return 0;
}