61132023-11-01 16:29:03GhostKarácsonyi égőkcpp17Accepted 100/100160ms26704 KiB
#include <iostream>
#include <vector>
#include <set>
#include <limits.h>

using namespace std;

int main()
{
    int n, c, i, out = INT_MAX;
    cin >> n >> c;

    vector<int> lights(n);
    for (i = 0; i < n; i++) {
        cin >> lights[i];
    }

    vector<int> colors(c, 0);
    set<int> present;

    int back = 0;
    i = 0;
    while (i < n) {
        if (present.size() < c) {
            present.insert(lights[i]);
            colors[lights[i]]++;
            i++;
        }
        if (present.size() == c) {
            if (out > i - back) {
                out = i - back;
            }
            colors[lights[back]]--;
            if (colors[lights[back]] == 0) {
                present.erase(lights[back]);
            }
            back++;
        }
    }
    cout << out;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2056 KiB
subtask215/15
3Accepted41ms3648 KiB
4Accepted39ms3812 KiB
5Accepted39ms3996 KiB
6Accepted3ms2724 KiB
7Accepted3ms2968 KiB
subtask310/10
8Accepted3ms3060 KiB
9Accepted3ms3272 KiB
10Accepted3ms3520 KiB
11Accepted3ms3764 KiB
12Accepted3ms3812 KiB
subtask420/20
13Accepted3ms3892 KiB
14Accepted3ms4120 KiB
15Accepted3ms4208 KiB
16Accepted3ms4324 KiB
17Accepted3ms4440 KiB
subtask525/25
18Accepted4ms5072 KiB
19Accepted4ms4952 KiB
20Accepted4ms4904 KiB
21Accepted4ms4892 KiB
22Accepted3ms4984 KiB
subtask630/30
23Accepted160ms26704 KiB
24Accepted61ms6096 KiB
25Accepted71ms6544 KiB
26Accepted104ms11356 KiB
27Accepted119ms16392 KiB
28Accepted71ms6596 KiB
29Accepted61ms6328 KiB
30Accepted39ms6328 KiB