/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 552.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++;
        while (zeroCount > k) {
            if (s[left] == '0') zeroCount--;
            left++;
        }
        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:32:01
Judged At
2025-02-17 15:32:01
Judged By
Score
0
Total Time
1ms
Peak Memory
552.0 KiB