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 ll long long int
#define inf 1e+18
using namespace std;
string s;
ll n,x=0,y=0,ans=0,d=0,o[27]={},t=1;
void Try(ll j){
ll q[27]={},k=0,z=0,o1,o2,m=-inf;
for (ll i=0;i<s.size();i++){
if (q[int(s[i])-96]==0) k++;
q[int(s[i])-96]++;
while (k>j){
q[int(s[z])-96]--;
if (q[int(s[z])-96]==0) k--;
z++;
}
if (k==j){
if (i-z+1>m){
m=i-z+1;
o1=i;
o2=z;
}
}
}
if (j*ans<t*m){
x=o1;
y=o2;
ans=m;
t=j;
}
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>s;
for (ll i=0;i<s.size();i++)
if (o[int(s[i])-96]==0){
d++;
o[int(s[i])-96]=1;
}
for (ll i=1;i<=d;i++)
Try(i);
cout<<y+1<<" "<<x+1;
}
Compilation message (stderr)
nivelle.cpp: In function 'void Try(long long int)':
nivelle.cpp:11:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for (ll i=0;i<s.size();i++){
| ~^~~~~~~~~
nivelle.cpp: In function 'int main()':
nivelle.cpp:39:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (ll i=0;i<s.size();i++)
| ~^~~~~~~~~
nivelle.cpp: In function 'void Try(long long int)':
nivelle.cpp:29:10: warning: 'o2' may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | y=o2;
| ~^~~
nivelle.cpp:28:10: warning: 'o1' may be used uninitialized in this function [-Wmaybe-uninitialized]
28 | x=o1;
| ~^~~
# | 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... |