Pagini recente » Cod sursa (job #212398) | Cod sursa (job #1078592) | Cod sursa (job #2385187) | Cod sursa (job #2614877) | Cod sursa (job #2957007)
#include <bits/stdc++.h>
using namespace std;
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
using i64 = long long int;
const int INF = INT_MAX, MOD = 1e9 + 7;
const long long LINF = LLONG_MAX;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {0, 0, 0, -1, 1, -1, 1, 1, -1};
const int dy[] = {0, -1, 1, 0, 0, -1, 1, -1, 1};
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
/// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ifstream cin("secv.in");
ofstream cout("secv.out");
int N; cin >> N;
vector<int> nums(N), aux(N), num_set;
for (int i = 0; i < N; i++) {
cin >> nums[i];
aux[i] = nums[i];
}
sort(aux.begin(), aux.end());
num_set.push_back(aux[0]);
for (auto num: aux)
if (num != num_set.back())
num_set.push_back(num);
int ans = N + 1;
for (int i = 0; i < N; i++) {
int pos = 0;
for (int j = i; j < N; j++) {
if (nums[j] == num_set[pos])
pos++;
if (pos == (int) num_set.size()) {
ans = min(j - i + 1, ans);
}
}
}
cout << (ans == N + 1 ? -1 : ans) << "\n";
return 0;
}