/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 532.0 KiB
#2 Wrong Answer 5ms 580.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    int maxConsecutiveOnes = 0, left = 0, zeroCount = 0;

    for (int right = 0; right < N; ++right) {
        if (S[right] == '0') zeroCount++;

        // If too many zeros, shrink the window
        while (zeroCount > K) {
            if (S[left] == '0') zeroCount--;
            left++;
        }

        // Maximum window with at most K zero flips
        maxConsecutiveOnes = max(maxConsecutiveOnes, right - left + 1);
    }

    cout << maxConsecutiveOnes << "\n";
}

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

    int T;
    cin >> T;
    while (T--) {
        solve();
    }

    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 14:46:11
Judged At
2025-02-17 14:46:11
Judged By
Score
0
Total Time
5ms
Peak Memory
580.0 KiB