| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
用了两个map= =#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int a[1000000+7],n;
map<int,int> fuck;
map<int,int> f;
int main()
{
// memset(a,0,sizeof(a));
scanf("%d",&n);
int count=0;
for (int i = 0; i < n; i += 1){
scanf("%d",&a[i]);
if(fuck[a[i]]==0){
count++;
}
fuck[a[i]]++;
}
int s=0,res=n+1,t=0,sum=0;
while (1)
{
while(t<n&&sum<count){
if(f[a[t]]==0)sum++;
f[a[t++]]++;
}
if(sum<count)break;
res=min(res,t-s);
f[a[s]]--;
if(f[a[s++]]==0)sum--;
}
cout<<res<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator