/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 2ms 488.0 KiB
#3 Wrong Answer 8ms 492.0 KiB
#4 Wrong Answer 7ms 336.0 KiB

Code

#define _GLIBCXX_FILESYSTEM
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

int n,k,q;
string s;

ll f(int x) {
    int now = 0, cnt = 0;
    ll tot = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == '?') {
            if(now < x) cnt++, now++;
            else if(now < q) tot += 1ll * cnt, now++;

        } else if(s[i] == 'A') cnt++;
        else if(s[i] == 'B') tot += 1ll * cnt;
    }
    return tot;
}

void solve() {
    cin >> n >> k >> s;
    q = 0;
    for(auto c: s) if(c == '?') q++;
    q = min(q, k);
    int l = 0, r = q, m1,m2;
    ll ans = 0;
    while(r - l + 1 >= 3) {
        m1 = l + (r - l) / 3;
        m2 = r - (r - l) / 3;
        ll f1 = f(m1), f2 = f(m2);
        if(f1 > f2) r = m2 - 1;
        else l = m1 + 1;
    } 
    for(int i = l; i <= r; i++) {
        ans = max(ans, f(i));
    }
    cout << ans << '\n';
    return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int tc = 1;
    cin >> tc;
    for(int kase = 1; kase <= tc; kase++) {
        //cout << "Case " << kase << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1110 Subsequence of AB
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 16:28:14
Judged At
2024-11-11 02:27:12
Judged By
Score
3
Total Time
8ms
Peak Memory
492.0 KiB