Mai intai trebuie sa te autentifici.
Cod sursa(job #2127393)
Utilizator | Data | 10 februarie 2018 16:52:44 | |
---|---|---|---|
Problema | Secv | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.41 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("secv.in");
ofstream fout("secv.out");
int n,st,v[5001],r[5001],s=1<<30;
int main(){
fin>>n;
for(int i=0;i<n;++i){fin>>v[i],r[i]=++v[i];}
sort(r,r+n);r[unique(r,r+n)-r]=0;
for(int j=n-1;j>=0;--j){st=0;
for(int i=j;i<n;++i){
if(v[i]==r[st]){++st;}
if(!r[st]){s=min(s,i-j+1);}
}
}
if(s!=1<<30){fout<<s;}
else {fout<<-1;}
}