6042 | 2023-10-28 18:57:13 | Gervid | Karácsonyi égők | cpp17 | Accepted 100/100 | 158ms | 28348 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> leds(n);
for (i = 0; i < n; i++)
{
cin >> leds[i];
}
vector<int> colors(c, 0);
set<int> present;
int back = 0;
i = 0;
while (i < n)
{
while (present.size() < c && i < n)
{
colors[leds[i]]++;
present.insert(leds[i]);
i++;
}
while (present.size() == c)
{
if (out > i - back)
{
out = i - back;
}
if (--colors[leds[back]] == 0)
{
present.erase(leds[back]);
}
back++;
}
}
cout << out;
}
//10 4
//0 1 3 0 0 1 2 0 2 3
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1804 KiB | ||||
2 | Accepted | 3ms | 1932 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 41ms | 4016 KiB | ||||
4 | Accepted | 41ms | 4636 KiB | ||||
5 | Accepted | 39ms | 5256 KiB | ||||
6 | Accepted | 3ms | 3988 KiB | ||||
7 | Accepted | 3ms | 3996 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 4040 KiB | ||||
9 | Accepted | 3ms | 4184 KiB | ||||
10 | Accepted | 3ms | 4396 KiB | ||||
11 | Accepted | 3ms | 4452 KiB | ||||
12 | Accepted | 3ms | 4456 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 4476 KiB | ||||
14 | Accepted | 3ms | 4464 KiB | ||||
15 | Accepted | 3ms | 4600 KiB | ||||
16 | Accepted | 3ms | 4680 KiB | ||||
17 | Accepted | 3ms | 4668 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 5468 KiB | ||||
19 | Accepted | 4ms | 5320 KiB | ||||
20 | Accepted | 4ms | 5512 KiB | ||||
21 | Accepted | 4ms | 5292 KiB | ||||
22 | Accepted | 4ms | 5308 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 158ms | 28348 KiB | ||||
24 | Accepted | 61ms | 8600 KiB | ||||
25 | Accepted | 70ms | 9752 KiB | ||||
26 | Accepted | 104ms | 15828 KiB | ||||
27 | Accepted | 123ms | 21892 KiB | ||||
28 | Accepted | 71ms | 13184 KiB | ||||
29 | Accepted | 61ms | 13656 KiB | ||||
30 | Accepted | 39ms | 13948 KiB |