/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 536.0 KiB

Code

#include <iostream>
#include <string>
#include <vector>
using namespace std;

long long countABSubsequences(string &s) {
    long long a_count = 0, ab_count = 0;
    for (char ch : s) {
        if (ch == 'A') {
            a_count++;
        } else if (ch == 'B') {
            ab_count += a_count;
        }
    }
    return ab_count;
}

void solve() {
    int n, k;
    string s;
    cin >> n >> k >> s;

    vector<int> question_positions;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '?') question_positions.push_back(i);
    }

    for (int i : question_positions) {
        if (k <= 0) break;
        if (i > 0 && s[i - 1] == 'A') {
            s[i] = 'B';
            k--;
        } else if (i < n - 1 && s[i + 1] == 'B') {
            s[i] = 'A';
            k--;
        }
    }

    long long result = countABSubsequences(s);
    cout << result << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Information

Submit By
Type
Pretest
Problem
P1110 Subsequence of AB
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 15:57:57
Judged At
2024-11-11 02:29:04
Judged By
Score
0
Total Time
1ms
Peak Memory
536.0 KiB