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;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
cin >> n >> s;
int last[26];
for (int i = 0; i < 26; i++) last[i] = -1;
int nu = 1, d = 1;
int l = 0, r = n - 1;
for (int i = 0; i < n; i++) {
last[s[i] - 'a'] = i;
vector<int> v;
for (int j = 0; j < 26; j++) v.push_back(last[j]);
sort(v.rbegin(), v.rend());
int j;
for (j = 1; j < 26; j++) {
if (v[j] == -1) break;
int nn = j;
int dd = i - v[j];
if (nu * dd >= d * nn) nu = nn, d = dd, l = v[j] + 1, r = i;
}
if (nu * (i + 1) >= d * j) nu = j, d = i + 1, l = 0, r = i;
}
cout << l + 1 << " " << r + 1 << "\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... |