63422023-11-21 10:04:50GervidSíkság (55)cpp17Wrong answer 50/5539ms9640 KiB
#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    int n, i, j, max, maxi;
    cin >> n;

	vector<int> terrain(n);

	for (i = 0; i < n; i++)
	{
		cin >> terrain[i];
	}

	map<int, int> dict;


	i = 0, j = 0, max = 0, maxi = 0;

	while (j < n)
	{
		auto it2 = dict.begin();

		if (dict.size() == 2)
		{
			it2++;
		}

		if (dict.size() <= 1 || (dict.size() == 2 && abs(dict.begin().operator*().first - it2.operator*().first) == 1))
		{
			if (max < j - i)
			{
				max = j - i;
				maxi = i;
			}

			if (dict.count(terrain[j]) == 0)
			{
				dict[terrain[j]] = 1;
			}
			else
			{
				dict[terrain[j]]++;
			}

			j++;
		}
		else
		{
			if (--dict[terrain[i]] == 0)
			{
				dict.erase(terrain[i]);
			}
			i++;
		}
	}

	cout << max << ' ' << maxi + 1;
}
SubtaskSumTestVerdictTimeMemory
base50/55
1Accepted0/03ms1812 KiB
2Accepted0/04ms2228 KiB
3Wrong answer0/23ms2256 KiB
4Accepted2/23ms2476 KiB
5Accepted2/23ms2588 KiB
6Accepted2/23ms2796 KiB
7Accepted3/33ms2912 KiB
8Accepted2/23ms3016 KiB
9Accepted3/33ms3128 KiB
10Accepted3/36ms3444 KiB
11Accepted3/34ms3596 KiB
12Wrong answer0/34ms3820 KiB
13Accepted3/337ms5068 KiB
14Accepted3/321ms5304 KiB
15Accepted3/329ms5736 KiB
16Accepted3/335ms6332 KiB
17Accepted3/337ms6892 KiB
18Accepted3/339ms7484 KiB
19Accepted3/337ms8060 KiB
20Accepted3/337ms8888 KiB
21Accepted3/320ms8924 KiB
22Accepted3/328ms9640 KiB