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>
using namespace std;
#ifdef DEBUG
#include "/Users/kutay/CP/templates/debug.h"
#else
#define debug(...) void(38)
#endif
#define int long long
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
string s; cin >> s;
double d = 1e9;
pair<int, int> ans;
for (int a = 1; a <= 26; a++) {
vector<int> m(26);
int l = 0, r = 0;
int cnt = 0;
while (r < n && cnt <= a) {
m[s[r++] - 'a']++;
int c = 0;
for (int x : m) c += (bool) x;
cnt = c;
if (c > a) {
r--;
break;
}
}
r--;
if ((double) a / (r - l + 1) - d < -1e-7) {
d = (double) a / (r - l + 1);
ans = make_pair(l, r);
}
debug(a, l, r, d);
while (r < n - 1) {
r++;
cnt = a;
while (r < n && cnt <= a + 1) {
m[s[r++] - 'a']++;
int c = 0;
for (int x : m) c += (bool) x;
cnt = c;
if (c > a + 1) {
r--;
break;
}
}
r--;
debug(l, r);
while (l < n && cnt > a) {
m[s[l++] - 'a']--;
int c = 0;
for (int x : m) c += (bool) x;
cnt = c;
}
l--;
debug(l, r);
if ((double) a / (r - l + 1) < d) {
d = (double) a / (r - l + 1);
ans = make_pair(l, r);
}
}
}
cout << ans.first + 1 << " " << ans.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... |