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 fi first
#define se second
using namespace std;
const int N=1e5;
struct Ans
{
int l,r;
int a,b;
bool operator<(const Ans &oth) const
{
return a*oth.b<oth.a*b;
}
};
int cnt[300];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
string s;
Ans ans={1,1,1,1};
cin>>n>>s;
for(int c=1;c<='z'-'a'+1;c++)
{
for(int i=1,j=0,tmp=0;i<=n;)
{
if(j<n && tmp<=c)
{
j++;
cnt[s[j-1]]++;
if(cnt[s[j-1]]==1)
tmp++;
}
else
{
cnt[s[i-1]]--;
if(cnt[s[i-1]]==0)
tmp--;
i++;
}
ans=min(ans,(Ans){i,j,tmp,j-i+1});
}
}
cout<<ans.l<<" "<<ans.r<<"\n";
return 0;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:32:15: warning: array subscript has type 'char' [-Wchar-subscripts]
32 | cnt[s[j-1]]++;
| ^
nivelle.cpp:33:18: warning: array subscript has type 'char' [-Wchar-subscripts]
33 | if(cnt[s[j-1]]==1)
| ^
nivelle.cpp:38:15: warning: array subscript has type 'char' [-Wchar-subscripts]
38 | cnt[s[i-1]]--;
| ^
nivelle.cpp:39:18: warning: array subscript has type 'char' [-Wchar-subscripts]
39 | if(cnt[s[i-1]]==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... |