-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFestival de musique.cpp
65 lines (52 loc) · 1.16 KB
/
Festival de musique.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
#define NB_GROUPES_MAX 100000
using namespace std;
deque<int> sequence;
vector<int> Groupes;
int nbJ, nbG;
bool isNotNull(int a) { return a != 0; }
int getFirstSequence() {
int x, i = 0;
while (!all_of(Groupes.begin(), Groupes.end(), isNotNull)) {
cin >> x;
Groupes[x - 1]++;
sequence.push_back(x);
i++;
}
return i;
}
void simplify() {
if (Groupes.empty()) return;
while (Groupes[sequence.front() - 1] > 1) {
Groupes[sequence.front() - 1]--;
sequence.pop_front();
}
}
void advance() {
int x;
cin >> x;
Groupes[x - 1]++;
Groupes[sequence.front() - 1]--;
sequence.pop_front();
sequence.push_back(x);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> nbJ >> nbG;
Groupes.assign(nbG, 0);
int currIndex = getFirstSequence();
simplify();
int mini = min(nbJ, (int)sequence.size());
while (currIndex < nbJ) {
advance();
if (all_of(Groupes.begin(), Groupes.end(), isNotNull)) {
simplify();
mini = min(mini, (int)sequence.size());
}
currIndex++;
}
cout << mini;
return 0;
}