-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmp.cpp
38 lines (36 loc) · 769 Bytes
/
tmp.cpp
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
36
37
38
#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
using namespace std;
int main(){
int m, n;
int ans = -1;
cin >> n >> m;
if(m < 1 || n < 1){
cout<<0<<endl;return 0;
}
if(m == 1 || n == 1){
cout<<1<<endl;return 0;
}
set<long>color_set;
queue<long>q;
long color;
for(int i = 0; i < n; i++){
scanf("%ld", &color);
color_set.insert(color);
q.push(color);
if(color_set.size() == m){
if(ans <= 0 || (ans > 0 && ans > q.size())){
ans = q.size();
}
}
if(color == q.front() && q.size() > 1){
q.pop();
}
}
cout << ans << endl;
q.empty();
color_set.empty();
return 0;
}