Cod sursa(job #1691582)

Utilizator MDiana15Diana M MDiana15 Data 18 aprilie 2016 20:02:37
Problema Secv Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#include <algorithm>
using namespace std;
int n,i,h,v[5001],a[5001],ok,j,min1=2000000000,in,ok1;
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++)
    {
        ok1=0;
        for(j=1; j<=h; j++)
        {
            if(v[i]==a[j])ok1=1;
        }
        if(ok1==0)
        {
            a[h]=v[i];
            h++;
        }
    }
    h--;
    sort(a+1,a+h+1);
    for(i=1; i<=n-h+1; i++)
    {
        in=1;
        ok=0;
        for(j=i; j<=n; j++)
        {
            if(a[in]==v[j])
            {
                in++;
                if(in>h)
                {
                    ok=1;
                    break;
                }
            }
        }
            if(ok==1)
            {
                if(min1>j-i+1)
                {
                    min1=j-i+1;
                }
            }

    }
    if(min1==2000000000)g<<"-1";
    else g<<min1;

    return 0;
}