6113 | 2023-11-01 16:29:03 | Ghost | Karácsonyi égők | cpp17 | Accepted 100/100 | 160ms | 26704 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 41ms | 3648 KiB | ||||
4 | Accepted | 39ms | 3812 KiB | ||||
5 | Accepted | 39ms | 3996 KiB | ||||
6 | Accepted | 3ms | 2724 KiB | ||||
7 | Accepted | 3ms | 2968 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 3060 KiB | ||||
9 | Accepted | 3ms | 3272 KiB | ||||
10 | Accepted | 3ms | 3520 KiB | ||||
11 | Accepted | 3ms | 3764 KiB | ||||
12 | Accepted | 3ms | 3812 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3892 KiB | ||||
14 | Accepted | 3ms | 4120 KiB | ||||
15 | Accepted | 3ms | 4208 KiB | ||||
16 | Accepted | 3ms | 4324 KiB | ||||
17 | Accepted | 3ms | 4440 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 5072 KiB | ||||
19 | Accepted | 4ms | 4952 KiB | ||||
20 | Accepted | 4ms | 4904 KiB | ||||
21 | Accepted | 4ms | 4892 KiB | ||||
22 | Accepted | 3ms | 4984 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 160ms | 26704 KiB | ||||
24 | Accepted | 61ms | 6096 KiB | ||||
25 | Accepted | 71ms | 6544 KiB | ||||
26 | Accepted | 104ms | 11356 KiB | ||||
27 | Accepted | 119ms | 16392 KiB | ||||
28 | Accepted | 71ms | 6596 KiB | ||||
29 | Accepted | 61ms | 6328 KiB | ||||
30 | Accepted | 39ms | 6328 KiB |