Cod sursa(job #2225874)

Utilizator Alex03Runcan Alexandru Alex03 Data 28 iulie 2018 15:32:12
Problema Secv Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("secv.in"); ofstream fout ("secv.out");
int n, nrdist, lim, lg, pos, sol, v[5001], temp[5000], dist[5001];

int main()
{
	fin >> n;
	for (int i = 1; i <= n; i++)
	{
		fin >> v[i];
		temp[i] = v[i];
	}
	sort(temp + 1, temp + n + 1);
	dist[++nrdist] = temp[1];
	for(int i = 2; i <= n; i++)
		if (temp[i - 1] != temp[i]) dist[++nrdist] = temp[i];
	sol = 5000;
	for(int i = 1; i <= n; i++)
	{
		int j = i, k = 1;
		while (j <= n && k <= nrdist)
		{
			if (v[j] == dist[k]) k++;
			j++;
		}
		if (j <= n || k > nrdist) sol = min (sol, j - i);
	}
	if (sol != 5000) fout << sol;
	else fout << -1;
	return 0;
}