# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119425 | ezzzay | Nivelle (COCI20_nivelle) | C++14 | 1055 ms | 592 KiB |
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 <string>
#include <unordered_map>
#include <limits>
using namespace std;
pair<int, int> findMinColorfulnessSubsequence(int N, const string& S) {
double minColorfulness = 1.0;
int bestL = 1, bestR = N;
for (int L = 0; L < N; L++) {
unordered_map<char, int> colorCount;
int uniqueColors = 0;
for (int R = L; R < N; R++) {
// Add current color if it's new
if (colorCount[S[R]]++ == 0) {
uniqueColors++;
}
// Calculate colorfulness
double colorfulness = 1.0 * uniqueColors / (R - L + 1);
// Update best subsequence
// Prioritize smaller colorfulness
// If colorfulness is same, prefer earlier subsequence
if (colorfulness < minColorfulness ||
(colorfulness == minColorfulness && (R - L + 1 < bestR - bestL + 1))) {
minColorfulness = colorfulness;
bestL = L + 1;
bestR = R + 1;
}
}
}
return {bestL, bestR};
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
string S;
cin >> N;
cin >> S;
auto [L, R] = findMinColorfulnessSubsequence(N, S);
cout << L << " " << R << endl;
return 0;
}
Compilation message (stderr)
# | 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... |