60422023-10-28 18:57:13GervidKarácsonyi égőkcpp17Accepted 100/100158ms28348 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
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1804 KiB
2Accepted3ms1932 KiB
subtask215/15
3Accepted41ms4016 KiB
4Accepted41ms4636 KiB
5Accepted39ms5256 KiB
6Accepted3ms3988 KiB
7Accepted3ms3996 KiB
subtask310/10
8Accepted3ms4040 KiB
9Accepted3ms4184 KiB
10Accepted3ms4396 KiB
11Accepted3ms4452 KiB
12Accepted3ms4456 KiB
subtask420/20
13Accepted3ms4476 KiB
14Accepted3ms4464 KiB
15Accepted3ms4600 KiB
16Accepted3ms4680 KiB
17Accepted3ms4668 KiB
subtask525/25
18Accepted4ms5468 KiB
19Accepted4ms5320 KiB
20Accepted4ms5512 KiB
21Accepted4ms5292 KiB
22Accepted4ms5308 KiB
subtask630/30
23Accepted158ms28348 KiB
24Accepted61ms8600 KiB
25Accepted70ms9752 KiB
26Accepted104ms15828 KiB
27Accepted123ms21892 KiB
28Accepted71ms13184 KiB
29Accepted61ms13656 KiB
30Accepted39ms13948 KiB