#include <iostream>
#include <string>
using namespace std;
const int N = 1e5 + 10;
int n, Log2[N], a[N][20];
string s;
int get(int l, int r) {
int kk = Log2[r - l + 1];
return a[l][kk] | a[r - (1 << kk) + 1][kk];
}
int Find(int i, int l, int val) {
int r = n, ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
int kk = __builtin_popcount(get(i, mid));
if (kk > val) r = mid - 1;
else {
ans = mid;
l = mid + 1;
}
}
return ans;
}
int main() {
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> n >> s;
s = " " + s;
for (int i = 1; i <= n; ++i) {
if (i >= 2) Log2[i] = Log2[i >> 1] + 1;
a[i][0] = 1 << (s[i] - 'a');
}
for (int j = 1; (1 << j) <= n; ++j) {
for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
a[i][j] = a[i][j - 1] | a[i + (1 << (j - 1))][j - 1];
}
}
double Min = 1e9;
int L, R;
for (int i = 1; i <= n; ++i) {
int la = i;
for (int j = 1; j <= 26; ++j) {
la = Find(i, la, j);
if (la == -1) break;
double cur = (double)j / (double)(la - i + 1);
if (cur < Min) {
Min = cur;
L = i;
R = la;
}
}
}
cout << L << " " << R << "\n";
return 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... |