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;
using ll = long long;
int main() {
int n, P=5000, Q=1, l=1, r=1;
string s;
cin >> n >> s;
map<char, vector<int> > mp;
for(int i=0; i<n; i++) mp[s[i]].push_back(i);
for(char ch='a'; ch<='z'; ch++) mp[ch].push_back(n);
for(int i=0; i<n; i++) {
vector<int> v;
for(char ch='a'; ch<='z'; ch++) {
int p = lower_bound(mp[ch].begin(), mp[ch].end(), i) - mp[ch].begin();
if(mp[ch][p] != n) v.push_back(mp[ch][p]);
}
sort(v.begin(), v.end());
if(v.back() != n) v.push_back(n);
for(int j=0; j<v.size()-1; j++) {
int A = j + 1, B = v[j+1] - i;
if(P * B > Q * A) {
P = A, Q = B;
l = i, r = v[j+1]-1;
}
}
}
cout << l+1 << " " << r+1 << '\n';
return 0;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int j=0; j<v.size()-1; j++) {
| ~^~~~~~~~~~~
# | 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... |