Submission #1119423

#TimeUsernameProblemLanguageResultExecution timeMemory
1119423ezzzayNivelle (COCI20_nivelle)C++14
24 / 110
1047 ms596 KiB
#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)

nivelle.cpp: In function 'int main()':
nivelle.cpp:47:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     auto [L, R] = findMinColorfulnessSubsequence(N, S);
      |          ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...