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;
const int N=1e5+5,S=26;
int n,sl,sr,c,len,k,cnt[S];
char s[N];
void add(int x,int v){
x-='a';
if(cnt[x]) k--;
cnt[x]+=v;
if(cnt[x]) k++;
}
int main(){
scanf("%d%s",&n,s+1);
for(int i=1;i<=S;i++) for(int l=1,r=1;l<=n;add(s[l++],-1)){
while(r<=n&&k<=i) add(s[r++],1);
int tr=r-(k>i);
if((tr-l)*c>=len*i) c=i,len=tr-l,sl=l,sr=tr-1;
}
printf("%d %d\n",sl,sr);
return 0;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%s",&n,s+1);
| ~~~~~^~~~~~~~~~~~~~~
# | 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... |