4410 | 2023-03-27 18:26:01 | balaaaazs | Karácsonyi égők | cpp14 | Accepted 100/100 | 119ms | 24684 KiB |
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main() {
int n, c;
cin >> n >> c;
vector<int> lights(n);
for (int i = 0; i < n; i++) {
cin >> lights[i];
}
unordered_map<int, int> colorCount;
int uniqueColors = 0;
int left = 0, right = 0;
int shortestSubsequence = n;
while (right < n) {
colorCount[lights[right]]++;
if (colorCount[lights[right]] == 1) {
uniqueColors++;
}
while (left <= right && colorCount[lights[left]] > 1) {
colorCount[lights[left]]--;
left++;
}
if (uniqueColors == c) {
shortestSubsequence = min(shortestSubsequence, right - left + 1);
}
right++;
}
cout << shortestSubsequence << endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1684 KiB | ||||
2 | Accepted | 3ms | 1844 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 52ms | 3280 KiB | ||||
4 | Accepted | 50ms | 3504 KiB | ||||
5 | Accepted | 50ms | 3716 KiB | ||||
6 | Accepted | 3ms | 2576 KiB | ||||
7 | Accepted | 3ms | 2916 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 3004 KiB | ||||
9 | Accepted | 3ms | 3096 KiB | ||||
10 | Accepted | 3ms | 3216 KiB | ||||
11 | Accepted | 3ms | 3360 KiB | ||||
12 | Accepted | 3ms | 3428 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3568 KiB | ||||
14 | Accepted | 3ms | 3804 KiB | ||||
15 | Accepted | 3ms | 3884 KiB | ||||
16 | Accepted | 3ms | 3868 KiB | ||||
17 | Accepted | 3ms | 3860 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 4464 KiB | ||||
19 | Accepted | 4ms | 4112 KiB | ||||
20 | Accepted | 4ms | 4444 KiB | ||||
21 | Accepted | 4ms | 4300 KiB | ||||
22 | Accepted | 4ms | 4304 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 119ms | 24684 KiB | ||||
24 | Accepted | 59ms | 5636 KiB | ||||
25 | Accepted | 64ms | 5544 KiB | ||||
26 | Accepted | 89ms | 10284 KiB | ||||
27 | Accepted | 98ms | 14964 KiB | ||||
28 | Accepted | 64ms | 5552 KiB | ||||
29 | Accepted | 64ms | 5708 KiB | ||||
30 | Accepted | 48ms | 5696 KiB |