/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 328.0 KiB
#2 Wrong Answer 1ms 544.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"] = max(charCount["AB"], charCount["AB"] + 1);
                maxOccurrence = max(maxOccurrence, charCount["AB"]);

                if (K > 0) {
                    modifiedS[i] = 'B';
                    modifiedS[i + 1] = 'A';
                    charCount["AB"] = max(charCount["AB"], 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
Submission
Problem
P1110 Subsequence of AB
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-09 07:23:53
Judged At
2024-11-11 02:22:35
Judged By
Score
0
Total Time
1ms
Peak Memory
544.0 KiB