44102023-03-27 18:26:01balaaaazsKarácsonyi égőkcpp14Accepted 100/100119ms24684 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1684 KiB
2Accepted3ms1844 KiB
subtask215/15
3Accepted52ms3280 KiB
4Accepted50ms3504 KiB
5Accepted50ms3716 KiB
6Accepted3ms2576 KiB
7Accepted3ms2916 KiB
subtask310/10
8Accepted3ms3004 KiB
9Accepted3ms3096 KiB
10Accepted3ms3216 KiB
11Accepted3ms3360 KiB
12Accepted3ms3428 KiB
subtask420/20
13Accepted3ms3568 KiB
14Accepted3ms3804 KiB
15Accepted3ms3884 KiB
16Accepted3ms3868 KiB
17Accepted3ms3860 KiB
subtask525/25
18Accepted4ms4464 KiB
19Accepted4ms4112 KiB
20Accepted4ms4444 KiB
21Accepted4ms4300 KiB
22Accepted4ms4304 KiB
subtask630/30
23Accepted119ms24684 KiB
24Accepted59ms5636 KiB
25Accepted64ms5544 KiB
26Accepted89ms10284 KiB
27Accepted98ms14964 KiB
28Accepted64ms5552 KiB
29Accepted64ms5708 KiB
30Accepted48ms5696 KiB