This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |