/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Wrong Answer 7ms 584.0 KiB
#3 Wrong Answer 9ms 580.0 KiB

Code

#include<bits/stdc++.h>
#define ll long long
#define endl '\n'

using namespace std;

int32_t main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        ll n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        int conseq_one = 0, one = 0, ans_conseq = 0;

        /*        for (int i = 0; i < n; i++) {
                    if (s[i] == '1') one++;
                }
        */

        for (int i = 0; i < n; i++) {
            conseq_one = 0;

            while (s[i] == '1' && i < n) {

                conseq_one++;
                one++;
                i++;
            }
            ans_conseq = max(ans_conseq, conseq_one);
        }
        int non_conseq = abs(one - ans_conseq);

        if (non_conseq <= k) cout << non_conseq + ans_conseq << endl;
        else {
            if (non_conseq >= k) cout << ans_conseq + k << endl;
            else cout << ans_conseq + non_conseq << endl;
        }

    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1159 Binary String
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 15:07:06
Judged At
2025-02-17 15:07:06
Judged By
Score
0
Total Time
9ms
Peak Memory
584.0 KiB