이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |