118052024-11-11 17:59:27MCDaveKarácsonyi égőkcpp17Accepted 100/10070ms1848 KiB
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, c, i, min, left = 0, x = 0;
    cin >> n >> c;
    vector<int> all(n), lights(c, 0);
    min = n - 1;

    for (i = 0; i < n; i++)
    {
        cin >> all[i];
        if (x < c and lights[all[i]] == 0)
        {
            x++;
            if (x == c) min = i;
        }
        lights[all[i]]++;
        while (x == c and lights[all[left]] > 1)
        {
            lights[all[left]]--, left++;
            if (i - left < min) min = i - left;
        }
    }

    cout << min + 1;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms320 KiB
subtask215/15
3Accepted35ms1080 KiB
4Accepted35ms1280 KiB
5Accepted35ms1080 KiB
6Accepted1ms404 KiB
7Accepted1ms320 KiB
subtask310/10
8Accepted1ms320 KiB
9Accepted1ms320 KiB
10Accepted1ms320 KiB
11Accepted1ms320 KiB
12Accepted1ms320 KiB
subtask420/20
13Accepted1ms320 KiB
14Accepted1ms320 KiB
15Accepted1ms320 KiB
16Accepted1ms320 KiB
17Accepted1ms320 KiB
subtask525/25
18Accepted2ms440 KiB
19Accepted2ms320 KiB
20Accepted2ms320 KiB
21Accepted2ms320 KiB
22Accepted2ms320 KiB
subtask630/30
23Accepted70ms1848 KiB
24Accepted46ms1196 KiB
25Accepted52ms1080 KiB
26Accepted64ms1336 KiB
27Accepted65ms1336 KiB
28Accepted52ms1080 KiB
29Accepted46ms1268 KiB
30Accepted35ms1080 KiB