/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 4ms 532.0 KiB

Code

#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

int findMaxOccurrence(string S, int K) {
    int n = S.length();
    int maxOccurrence = 0;
    unordered_map<string, int> charCount;

    // Try all possible modifications to the string
    for (int i = 0; i < n - 1; i++) {
        if (S[i] == '?' || S[i] == 'A') {
            if (S[i + 1] == '?' || S[i + 1] == 'B') {
                string modifiedS = S;
                modifiedS[i] = 'A';
                modifiedS[i + 1] = 'B';
                charCount["AB"] += 1;
                maxOccurrence = max(maxOccurrence, charCount["AB"]);

                if (K > 0) {
                    modifiedS[i] = 'B';
                    modifiedS[i + 1] = 'A';
                    charCount["AB"] += 1;
                    maxOccurrence = max(maxOccurrence, charCount["AB"]);
                    K--;
                }
            }
        }
    }

    return maxOccurrence;
}

int main() {
    int T; // Number of test cases
    cin >> T;

    for (int i = 0; i < T; i++) {
        int N, K; // Length of string and maximum operations
        cin >> N >> K;

        string S; // Input string
        cin >> S;

        cout << findMaxOccurrence(S, K) << endl;
    }

    return 0;
}

Information

Submit By
Type
Pretest
Problem
P1110 Subsequence of AB
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 16:06:24
Judged At
2024-11-05 16:06:24
Judged By
Score
0
Total Time
4ms
Peak Memory
532.0 KiB