117822024-11-10 17:59:35MittomenKarácsonyi égőkcpp17Accepted 100/10071ms1268 KiB
#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

int main() {
	int n, c;
	vector<int> lights;
	vector<bool> colors;
	int colors_found = 0;

	cin >> n >> c;

	lights.resize(n);
	colors.resize(c);

	for (int& li : lights) {
		cin >> li;
	}

	int r = 0;
	while (colors_found != c) {
		if (!colors[lights[r]]) colors_found++;

		colors[lights[r]] = true;

		r++;
	}

	colors_found = 0;
	int l = r;
	colors.clear();
	colors.resize(c);
	while (colors_found != c) {
		if (!colors[lights[l]]) colors_found++;

		colors[lights[l]] = true;

		l--;
	}

	cout << r - l - 1;

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms320 KiB
2Accepted1ms320 KiB
subtask215/15
3Accepted37ms1080 KiB
4Accepted37ms1080 KiB
5Accepted37ms1080 KiB
6Accepted1ms320 KiB
7Accepted1ms320 KiB
subtask310/10
8Accepted1ms320 KiB
9Accepted1ms320 KiB
10Accepted1ms320 KiB
11Accepted1ms500 KiB
12Accepted1ms320 KiB
subtask420/20
13Accepted2ms508 KiB
14Accepted1ms544 KiB
15Accepted1ms508 KiB
16Accepted1ms320 KiB
17Accepted1ms320 KiB
subtask525/25
18Accepted3ms320 KiB
19Accepted2ms320 KiB
20Accepted2ms320 KiB
21Accepted2ms320 KiB
22Accepted2ms320 KiB
subtask630/30
23Accepted71ms1080 KiB
24Accepted48ms1196 KiB
25Accepted54ms1128 KiB
26Accepted65ms1080 KiB
27Accepted68ms1268 KiB
28Accepted54ms1196 KiB
29Accepted48ms1080 KiB
30Accepted37ms1080 KiB