-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1208B.cpp
More file actions
35 lines (31 loc) · 775 Bytes
/
1208B.cpp
File metadata and controls
35 lines (31 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
vector<int> v(n, 0);
for(int i = 0; i < n; i++) {
cin >> v[i];
}
unordered_set<int> s;
int pre = 0;
for(; pre < n && !s.count(v[pre]); pre++) {
s.insert(v[pre]);
}
pre--;
int ans = n - pre - 1;
for(int i = n - 1; i > pre && pre >= 0; i--) {
while(s.count(v[i]) && pre >= 0 && v[pre] != v[i]) {
s.erase(v[pre--]);
}
if(s.count(v[i]) && pre >= 0) s.erase(v[pre--]);
ans = min(ans, i - pre - 1);
s.insert(v[i]);
}
s.clear();
for(int i = n - 1; i >= 0 && !s.count(v[i]); i--) {
s.insert(v[i]);
ans = min(ans, i);
}
cout << ans << endl;
return 0;
}