Pagini recente » Cod sursa (job #2870423) | Cod sursa (job #1691575)
#include <fstream>
#include <algorithm>
using namespace std;
int n,i,h,v[5001],a[5001],ok,j,min1=2000000000,ok1=0,in;
int main()
{
ifstream f("secv.in");
ofstream g("secv.out");
f>>n;h=1;
for(i=1;i<=n;i++)
{f>>v[i];}
for(i=1;i<=n;i++)
{ok=0;
for(j=1;j<=h;j++)
{if(v[i]==a[j])ok=1;}
if(ok==0){a[h]=v[i];h++;}}
h--;
sort(a+1,a+h+1);
for(i=1;i<=n;i++)
{
if(v[i]==1)
{in=2;ok=0;
for(j=i+1;j<=n;j++)
{
if(a[in]==v[j])in++;
if(in==h+1){ok=1;
if(j-i+1<min1){min1=j-i+1;}
break;}
}
if(ok==1){ok1=1;}
}}
if(ok1==0)g<<"-1";
else if(ok1==1)g<<min1;
return 0;
}