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 <iostream>
#include <algorithm>
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
int bestl = 1;
int bestr = 1;
int64_t bestcol = 1;
int64_t bestlen = 1;
int *lettercount = new int[26];
for (int maxcolors = 1; maxcolors < 27; maxcolors++){
for (int i = 0; i < 26; i++) lettercount[i] = 0;
int colors = 1;
int end = 1;
lettercount[s[0] - 'a'] = 1;
for (int start = 0; start < n; start++){
if (start != 0){
if (lettercount[s[start - 1] - 'a'] == 1) colors--;
lettercount[s[start - 1] - 'a']--;
}
while (end < n && (colors < maxcolors || lettercount[s[end] - 'a'] > 0)){
if (lettercount[s[end] - 'a'] == 0) colors++;
lettercount[s[end] - 'a']++;
end++;
}
if (colors * bestlen < (end - start) * bestcol){
bestl = start + 1;
bestr = end;
bestcol = colors;
bestlen = end - start;
}
}
}
cout << bestl << " " << bestr << endl;
}
# | 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... |