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 sz(c) int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
#define num first
#define den second
using namespace std;
using ll = long long;
using frac = pair<int,int>;
int N;
string S;
pair<frac,pair<int,int>> res;
void check_res(int a,int b,int l,int r) {
if (res.first.num*b>res.first.den*a) {
res={frac(a,b),make_pair(l,r)};
}
}
void solve(int c) {
map<int,int> cnt;
auto dec=[&](int i) {
cnt[i]--;
if (cnt[i]==0) cnt.erase(i);
};
int l=0;
rep(r,0,N) {
cnt[S[r]-'a']++;
while (l<r && sz(cnt)>c) dec(S[l++]-'a');
check_res(sz(cnt),r-l+1,l,r);
}
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout<<fixed<<setprecision(10);
cin>>N>>S;
set<char> ss(S.begin(),S.end());
res={frac(sz(ss),N),make_pair(0,N-1)};
rep(i,1,27) solve(i);
cout<<res.second.first+1<<" "<<res.second.second+1<<'\n';
}
# | 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... |