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 int long long
using namespace std;
const int N = 1e5 + 42, INF = 1e18 + 42;
string str;
int n, a = INF, b = 1, l = -1, r = -1, val[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> str;
for(int i = 0; i < n; i++)
val[i] = str[i] - 'a';
for(int i = 1; i <= 26; i++) {
int fin = 0, occ[26] = {0}, t = 0;
for(int deb = 0; deb < n; deb++) {
while(fin < n && ((occ[val[fin]] && t == i) || t < i)) {
if(!occ[val[fin]])
t++;
occ[val[fin]]++;
fin++;
}
if(a * (fin - deb) > b * i) {
l = deb, r = fin;
a = i, b = (fin - deb);
}
occ[val[deb]]--;
if(!occ[val[deb]])
t--;
}
}
cout << l+1 << ' ' << r;
}
# | 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... |