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;
int n, a=1, b=1, l=1, r=1, lst[27];
string s;
set<int> ms;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>s;
for (int i=0; i<26; i++) lst[i]=1;
ms.insert(1);
for (int i=0; i<n; i++)
{
if (lst[s[i]-'a']!=1) ms.erase(lst[s[i]-'a']);
lst[s[i]-'a']=-i;
ms.insert(-i);
int cnt=0;
for (auto x:ms)
{
int tmp=-x;
cnt++;
if (cnt>1)
{
if (a*(i-tmp)>b*(cnt-1)) a=cnt-1, b=i-tmp, l=tmp+2, r=i+1;
//cout<<"debug "<<i<<' '<<tmp<<' '<<a<<' '<<b<<' '<<cnt-1<<' '<<i-tmp<<'\n';
}
}
}
cout<<l<<' '<<r;
}
# | 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... |