Submission #1119425

#TimeUsernameProblemLanguageResultExecution timeMemory
1119425ezzzayNivelle (COCI20_nivelle)C++14
24 / 110
1055 ms592 KiB
#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)

nivelle.cpp: In function 'int main()':
nivelle.cpp:50:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |     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...