60702023-10-29 15:46:47GhostKarácsonyi égőkcpp17Time limit exceeded 30/1001.6s5308 KiB
#include <iostream>
#include <vector>
#include <set>
#include <limits.h>

using namespace std;

bool check(int c, set<int> colors) {
    for (int i = 0; i < c; i++) {
        if (colors.count(i) == 0) {
            return 0;
        }
    }
    return 1;
}

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

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

    set<int> colors;
    int minPOSlength = n;
    for (i = 0; i < n-c; i++) {
        int length = 1, start = lights[i], j = i+1;
        colors.insert(start);
        while (!check(c, colors) && j != n) {
            colors.insert(lights[j]);
            j++, length++;
        }
        if (length < minPOSlength && length >= c && check(c, colors)) {
            minPOSlength = length;
        }
        if (minPOSlength == c) {
            break;
        }
        colors.clear();
    }
    cout << minPOSlength;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted3ms2052 KiB
subtask20/15
3Time limit exceeded1.6s2308 KiB
4Time limit exceeded1.557s2468 KiB
5Time limit exceeded1.569s2688 KiB
6Accepted35ms2724 KiB
7Accepted28ms2844 KiB
subtask310/10
8Accepted2ms2840 KiB
9Accepted3ms2720 KiB
10Accepted3ms2852 KiB
11Accepted3ms3108 KiB
12Accepted3ms3344 KiB
subtask420/20
13Accepted328ms3500 KiB
14Accepted39ms3588 KiB
15Accepted9ms3572 KiB
16Accepted495ms3592 KiB
17Accepted79ms3724 KiB
subtask50/25
18Accepted4ms3792 KiB
19Time limit exceeded1.6s4016 KiB
20Time limit exceeded1.577s3988 KiB
21Time limit exceeded1.557s3944 KiB
22Accepted791ms3972 KiB
subtask60/30
23Accepted70ms5308 KiB
24Time limit exceeded1.56s4048 KiB
25Time limit exceeded1.565s4112 KiB
26Time limit exceeded1.557s4748 KiB
27Time limit exceeded1.562s4788 KiB
28Time limit exceeded1.557s4424 KiB
29Time limit exceeded1.572s4520 KiB
30Time limit exceeded1.574s4276 KiB