/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 3ms 544.0 KiB

Code

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int maxConsecutiveOnes(string &s, int n, int k) {
    int maxLen = 0;
    int left = 0, zeroCount = 0;

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

        // If more than `K` zeroes, shrink window
        while (zeroCount > k) {
            if (s[left] == '0') zeroCount--;
            left++;
        }

        // Update max length
        maxLen = max(maxLen, right - left + 1);
    }

    return maxLen;
}

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n, k;
        string s;
        cin >> n >> k >> s;

        cout << maxConsecutiveOnes(s, n, k) << endl;
    }

    return 0;
}

Information

Submit By
Type
Pretest
Problem
P1159 Binary String
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 15:30:46
Judged At
2025-02-17 15:30:46
Judged By
Score
0
Total Time
3ms
Peak Memory
544.0 KiB