6070 | 2023-10-29 15:46:47 | Ghost | Karácsonyi égők | cpp17 | Time limit exceeded 30/100 | 1.6s | 5308 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 0/15 | ||||||
3 | Time limit exceeded | 1.6s | 2308 KiB | ||||
4 | Time limit exceeded | 1.557s | 2468 KiB | ||||
5 | Time limit exceeded | 1.569s | 2688 KiB | ||||
6 | Accepted | 35ms | 2724 KiB | ||||
7 | Accepted | 28ms | 2844 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 2ms | 2840 KiB | ||||
9 | Accepted | 3ms | 2720 KiB | ||||
10 | Accepted | 3ms | 2852 KiB | ||||
11 | Accepted | 3ms | 3108 KiB | ||||
12 | Accepted | 3ms | 3344 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 328ms | 3500 KiB | ||||
14 | Accepted | 39ms | 3588 KiB | ||||
15 | Accepted | 9ms | 3572 KiB | ||||
16 | Accepted | 495ms | 3592 KiB | ||||
17 | Accepted | 79ms | 3724 KiB | ||||
subtask5 | 0/25 | ||||||
18 | Accepted | 4ms | 3792 KiB | ||||
19 | Time limit exceeded | 1.6s | 4016 KiB | ||||
20 | Time limit exceeded | 1.577s | 3988 KiB | ||||
21 | Time limit exceeded | 1.557s | 3944 KiB | ||||
22 | Accepted | 791ms | 3972 KiB | ||||
subtask6 | 0/30 | ||||||
23 | Accepted | 70ms | 5308 KiB | ||||
24 | Time limit exceeded | 1.56s | 4048 KiB | ||||
25 | Time limit exceeded | 1.565s | 4112 KiB | ||||
26 | Time limit exceeded | 1.557s | 4748 KiB | ||||
27 | Time limit exceeded | 1.562s | 4788 KiB | ||||
28 | Time limit exceeded | 1.557s | 4424 KiB | ||||
29 | Time limit exceeded | 1.572s | 4520 KiB | ||||
30 | Time limit exceeded | 1.574s | 4276 KiB |