이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <string>
#include <unordered_map>
#include <limits>
using namespace std;
pair<int, int> findMinimalColorfulnessSubsequence(const string& S) {
int N = S.size();
unordered_map<char, int> colorFrequency;
int uniqueColors = 0;
int left = 0, right = 0;
int minL = 0, minR = 0;
double minColorfulness = numeric_limits<double>::max();
for (right = 0; right < N; ++right) {
char currentColor = S[right];
// Add current toy to the window
if (colorFrequency[currentColor] == 0) {
uniqueColors++;
}
colorFrequency[currentColor]++;
// Try to shrink the window while keeping it valid
while (true) {
char leftColor = S[left];
if (colorFrequency[leftColor] > 1) {
colorFrequency[leftColor]--;
left++;
} else {
break;
}
}
// Calculate colorfulness for the current window
int windowSize = right - left + 1;
double currentColorfulness = (double)uniqueColors / windowSize;
// Update the result if a smaller colorfulness is found
if (currentColorfulness < minColorfulness) {
minColorfulness = currentColorfulness;
minL = left;
minR = right;
}
}
// Convert to 1-based indices
return {minL + 1, minR + 1};
}
int main() {
int N;
string S;
cin >> N >> S;
auto result = findMinimalColorfulnessSubsequence(S);
cout << result.first << " " << result.second << endl;
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... |