제출 #256660

#제출 시각아이디문제언어결과실행 시간메모리
256660MrRobot_28Nivelle (COCI20_nivelle)C++17
110 / 110
114 ms768 KiB
#include<bits/stdc++.h>
 
using namespace std;
#define int long long
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = n;
	int l = 0, r = n - 1;
	vector <int> end(26, -1);
	for(int i = 0; i < n; i++)
	{
		vector <int> mass;
		end[s[i] - 'a'] = i;
		for(int j = 0; j < 26; j++){
			if(end[j] != -1)
			{
				mass.push_back(end[j]);
			}
		}
		sort(mass.begin(), mass.end());
		int c = 0;
		for(int j = mass.size() - 1; j >= 0; j--)
		{
			if(mass[j] < i)
			{
				if(cnt * (i - mass[j]) > c * (r - l + 1))
				{
					l = mass[j] + 1;
					r = i;
					cnt = c;
				}
			}
			c++;
		}
		if(cnt * (i + 1) > c * (r - l + 1))
		{
			l = 0;
			r = i;
			cnt = c;
		}
	}
	cout << l + 1 << " " << r + 1;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...