#include <bits/stdc++.h>
#define int long long
using namespace std;
int a;
string s;
struct node{
int x,y,l,r;
};
node z[1000005];
bool cmp(node a,node b){
return a.x*b.y>b.x*a.y;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a;
cin >> s;
s='#'+s;
for (int i=1;i<=26;i++){
int l=1;
int r=1;
int cnt[27]={0};
int cur=0;
int max1=0,pos1=0,pos2=0;
while (r<=a){
cnt[s[r]-'a']++;
if (cnt[s[r]-'a']==1){
cur++;
}
while (l<=r && cur>i){
cnt[s[l]-'a']--;
if (cnt[s[l]-'a']==0){
cur--;
}
l++;
}
if (cur==i){
if (max1<r-l+1){
max1=r-l+1;
pos1=l;
pos2=r;
}
}
r++;
}
z[i]={max1,i,pos1,pos2};
}
sort(z+1,z+1+26,cmp);
cout << z[1].l << " " << z[1].r << "\n";
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... |