Cod sursa(job #1691572)

Utilizator MDiana15Diana M MDiana15 Data 18 aprilie 2016 19:37:47
Problema Secv Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <algorithm>
using namespace std;
int n,i,h,v[5001],a[5001],ok,j,min1=5001,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 g<<min1;

    return 0;
}