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 <iostream>
#include <bits/stdc++.h>
#include <bitset>
#include <algorithm>
using namespace std;
int n,freq[26],d,r,tmax,best[27][3];
string input;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>input;
for(int i=1;i<=26;i++)
{
for(int y=0;y<26;y++)freq[y]=0;
d=0;
r=0;
for(int l=0;l<n;l++)
{
if(l!=0)
{
if(freq[input[l-1]-'a']==1)d--;
freq[input[l-1]-'a']--;
}
while(r<n)
{
if(d==i&&freq[input[r]-'a']==0)break;
if(freq[input[r]-'a']==0)d++;
freq[input[r]-'a']++;
r++;
}
//cout<<" "<<l<<" "<<r<<"\n";
if(r-l>best[i][0])
{
best[i][0]=r-l;
best[i][1]=l;
best[i][2]=r;
}
}
}
//for(int i=1;i<=26;i++)cout<<best[i][0]<<" "<<best[i][1]<<" "<<best[i][2]<<"\n";
double check=0;
int oleft=0;
int oright=0;
for(int i=1;i<=26;i++)
{
if((double)best[i][0]/(double)i>check)
{
check=(double)best[i][0]/(double)i;
oleft=best[i][1];
oright=best[i][2];
}
}
cout<<oleft+1<<" "<<oright;
}
# | 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... |