62472023-11-08 13:47:34EsVagyKarácsonyi égőkcpp17Accepted 100/10071ms7676 KiB
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <climits>

using namespace std;

int main()
{
	int l, c;
	cin >> l >> c;

	vector<int> colors(c);
	int includedColors = 0;
	vector<int> line;
	for (int i = 0; i < l; i++)
	{
		int next;
		cin >> next;
		line.push_back(next);
	}


	int start = 0;
	int end = 0;
	int ans = INT_MAX;

	while (end != l)
	{
		if (colors[line[end]] == 0)
		{
			includedColors++;
		}
		colors[line[end]]++;

		while (colors[line[start]] > 1)
		{
			colors[line[start]]--;
			start++;
		}

		if (includedColors == c)
		{
			ans = min(ans, end - start + 1);
		}
		
		end++;
	}

	cout << ans;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted3ms2060 KiB
subtask215/15
3Accepted39ms4336 KiB
4Accepted39ms4620 KiB
5Accepted39ms4832 KiB
6Accepted3ms2892 KiB
7Accepted3ms3136 KiB
subtask310/10
8Accepted3ms3224 KiB
9Accepted2ms3316 KiB
10Accepted3ms3524 KiB
11Accepted2ms3612 KiB
12Accepted3ms3636 KiB
subtask420/20
13Accepted3ms3680 KiB
14Accepted3ms3920 KiB
15Accepted3ms3912 KiB
16Accepted3ms3916 KiB
17Accepted3ms4156 KiB
subtask525/25
18Accepted4ms4192 KiB
19Accepted4ms4144 KiB
20Accepted4ms4152 KiB
21Accepted4ms4208 KiB
22Accepted4ms4216 KiB
subtask630/30
23Accepted71ms7676 KiB
24Accepted50ms6120 KiB
25Accepted56ms6280 KiB
26Accepted67ms6520 KiB
27Accepted68ms7124 KiB
28Accepted56ms6208 KiB
29Accepted50ms6204 KiB
30Accepted39ms6328 KiB