Pagini recente » Cod sursa (job #530967) | Cod sursa (job #179832) | Cod sursa (job #1758315) | Cod sursa (job #1848889) | Cod sursa (job #72164)
Cod sursa(job #72164)
#include<stdio.h>
#define v 5002
long n,a[v],c[v],l,lung,max,q,e;
void citire()
{
freopen("secv.in","r",stdin);
scanf("%ld", &n);
max=0;
int x[2000000000];
q=-1;
for (int i=0; i<n; i++)
{
scanf("%ld", &a[i]);
if (x[a[i]]==0)
{
c[++q]=a[i];
x[a[i]]=1;
}
if (a[i]>max)
max=a[i];
}
fclose(stdin);
}
void radx(long max,long zero[v],long n)
{
long z,u,j;
int unu[v];
for (long i=0; i<max; i++)
{
z=-1;
u=-1;
for (j=0; j<n; j++)
{
if (((zero[j] >> i) &1)==0)
zero[++z]=zero[j];
else unu[++u]=zero[j];
}
u=-1;
for (j=z+1; j<n; j++)
zero[j]=unu[++u];
}
}
int nr_pasi(long max1)
{
int pas=0;
while (max1>0)
{
++pas;
max1>>=1;
}
return pas;
}
void rezolvare()
{
for (int i=0; i<n; i++)
{
if (a[i]==c[0])
{
e=1;
for (int j=i+1; j<n; j++)
{
if (a[j]==c[e])
e++;
if (e==q+1)
{
l=j-i+1;
if (j-i+1<lung)
lung=j-i+1;
break;
}
}
// if (l<lung)
// lung=l;
}
}
}
void scriere()
{
freopen("secv.out","w",stdout);
if (lung==6000)
printf("-1");
else printf("%ld", lung);
fclose(stdout);
}
int main()
{
lung=6000;
citire();
max=nr_pasi(max);
radx(max,c,q+1);
rezolvare();
scriere();
return 0;
}