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,ct,l,r,ac[150],j;
string s;
double best;
int main()
{
cin>>n>>s;
s=' '+s;
for (int k=1;k<=26;k++){
memset(ac,0,sizeof(ac));
ct=0,j=0;
for (int i=1;i<=n;i++){
while (j<n&&ct<=k){
j++;
if (ac[s[j]-'a']==0){
if (ct+1>k) {
j--;
break;
}
ct++;
}
ac[s[j]-'a']++;
}
//if (ct==2) cout<<i<<" "<<j<<" "<<ct<<"\n";
if (l==0||best>k/(double)(j-i+1)){
best=k/(double)(j-i+1);
l=i,r=j;
}
ac[s[i]-'a']--;
if (ac[s[i]-'a']==0) ct--;
}
}
cout<<l<<" "<<r<<"\n";
}
# | 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... |