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>
#define int long long
using namespace std;
int32_t main(){
int n;cin>>n;
string str;cin>>str;
vector<int> ilk(26,-1);
vector<int> kuc(26,0);
int frac1=1,frac2=1;
int ansl=0,ansr=0;
for (int i = n-1; i >= 0; i--){
ilk[str[i]-'a']=i;
int crr = 0;
for (int j = 0; j < 26; ++j)
{
if (ilk[j]!=-1) crr++;
}
if (crr*frac2<(n-i+1)*frac1){
frac1=crr;
frac2=n-i+1;
ansl=i;
ansr=n-1;
}
for (int j = 0; j < 26; j++){
if (ilk[j]==-1) continue;
if (ilk[j]==i) continue;
int crrr = 0;
for (int k = 0; k < 26; k++){
if (ilk[k]!=-1 && ilk[k]<=ilk[j]-1){
crrr++;
}
}
if (crrr==0) continue;
if (crrr*frac2<(ilk[j]-i)*frac1){
frac1=crrr;
frac2=ilk[j]-i;
ansl=i;
ansr=ilk[j]-1;
}
}
}
cout<<ansl+1<<" "<<ansr+1<<endl;
}
# | 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... |