/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 121ms 13.965 MiB
#2 Wrong Answer 119ms 13.715 MiB
#3 Wrong Answer 119ms 13.914 MiB

Code

function maxABSubsequence(T, testCases) {
    const results = [];

    for (let t = 0; t < T; t++) {
        const [N, K] = testCases[t][0];
        let S = testCases[t][1].split('');
        
        let countA = 0;
        let abCount = 0;
        let usedOperations = 0;

        for (let i = 0; i < N; i++) {
            if (S[i] === 'A') {
                countA++;  // Increment "A" count
            } else if (S[i] === 'B') {
                abCount += countA;  // "AB" subsequence count increment
            } else if (S[i] === '?' && usedOperations < K) {
                // Decide based on maximizing AB sequences
                if (countA > 0) {
                    S[i] = 'B';
                    abCount += countA;
                } else {
                    S[i] = 'A';
                    countA++;
                }
                usedOperations++;
            }
        }

        results.push(abCount);
    }
    
    return results.join("\n");
}

// Example usage:
const T = 2;
const testCases = [
    [[6, 2], "AABC?B"],
    [[3, 3], "?B?"]
];

console.log(maxABSubsequence(T, testCases));

Information

Submit By
Type
Submission
Problem
P1110 Subsequence of AB
Contest
Brain Booster #7
Language
JavaScript (Node.js v18.19.1)
Submit At
2024-11-05 15:02:20
Judged At
2024-11-05 15:02:20
Judged By
Score
1
Total Time
121ms
Peak Memory
13.965 MiB