/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 1ms 540.0 KiB
#3 Wrong Answer 6ms 580.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
    int a, b, gap_a, gap_b;
};
void solve()
{
    int n, k; cin >> n >> k;

    string s; cin >> s;
    vector<node> cnt(n);
    int a = 0, b = 0,gap = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'A')a++;
        if(s[i] == '?')gap++;
        cnt[i].a = a;
        cnt[i].gap_a = gap;
    }
    gap = 0;
    for(int i = n - 1; i >= 0 ; i--){
        cnt[i].b = b;
        cnt[i].gap_b = gap;
        if(s[i] == '?')gap++;
        if(s[i] == 'B')b++;
    }


    //a = 0, b = 0, gap = 0;
//    if(k >= gap){
//       ll mx = 0;
//        for(int i = 0; i < n; i++){
//            int tot_a = cnt[i].a + cnt[i].gap_a;
//            int tot_b = cnt[i].b + cnt[i].gap_b;
//            mx = max(mx, 1LL * tot_a * tot_b);
//        }
//
//        cout << mx << "\n";
//    }
//    else{
        k = min(k, gap);
        ll mx = 0;
        for(int i = 0; i < n; i++){
            int tmp_k = k;
            int tmp1 = cnt[i].a, tmp2 = cnt[i].b;
            if(tmp1 >= tmp2){
                int diff = tmp1 - tmp2;

                if(diff >= tmp_k){
                    tmp2 = tmp1;
                    tmp_k -= diff;
                    tmp1 += tmp_k / 2;
                    tmp2 += tmp_k - (tmp_k / 2);
                }
                else{
                    tmp2 += tmp_k;
                }
            }
            else{
                int diff = tmp2 - tmp1;

                if(diff >= tmp_k){
                    tmp1 = tmp2;
                    tmp_k -= diff;
                    tmp1 += tmp_k / 2;
                    tmp2 += tmp_k - (tmp_k / 2);
                }
                else{
                    tmp1 += tmp_k;
                }
            }
            mx = max(mx, 1LL * tmp1 * tmp2);
        }

        cout << mx << "\n";

//    }

}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	int t; cin >> t;

	while(t--){
        solve();
	}
}

Information

Submit By
Type
Submission
Problem
P1110 Subsequence of AB
Contest
LU IUJPC : Sylhet Division 2024, Mock Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-07 11:42:49
Judged At
2024-12-07 11:42:49
Judged By
Score
1
Total Time
6ms
Peak Memory
580.0 KiB