# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119423 | ezzzay | Nivelle (COCI20_nivelle) | C++14 | 1047 ms | 596 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_set>
#include <vector>
#include <limits>
using namespace std;
pair<int, int> findMinColorfulnessSubsequence(int N, const string& S) {
double minColorfulness = numeric_limits<double>::max();
int bestL = 1, bestR = 1;
// Try all possible contiguous subsequences
for (int L = 0; L < N; L++) {
// Track unique colors in current subsequence
unordered_set<char> uniqueColors;
for (int R = L; R < N; R++) {
// Add current toy's color to the set
uniqueColors.insert(S[R]);
// Calculate colorfulness
double colorfulness = 1.0 * uniqueColors.size() / (R - L + 1);
// Update best subsequence if current colorfulness is smaller
// Use <= to prefer earlier subsequences if colorfulness is same
if (colorfulness <= minColorfulness) {
minColorfulness = colorfulness;
bestL = L + 1; // Convert to 1-based indexing
bestR = R + 1;
}
}
}
return {bestL, bestR};
}
int main() {
// Input N and the string of toy colors
int N;
string S;
cin >> N;
cin >> S;
// Find and output the subsequence with minimal colorfulness
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... |