/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 332.0 KiB
#2 Wrong Answer 13ms 772.0 KiB

Code

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

using namespace std;

int maxConsecutiveOnes(string s, int n, int k) {
    int left = 0, right = 0, max_ones = 0, zeros_count = 0;

    while (right < n) {
        if (s[right] == '0') {
            zeros_count++;
        }

        while (zeros_count > k) {
            if (s[left] == '0') {
                zeros_count--;
            }
            left++;
        }

        max_ones = max(max_ones, right - left + 1);
        right++;
    }

    return max_ones;
}

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

    int t;
    cin >> t;

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

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

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1159 Binary String
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 08:06:40
Judged At
2025-02-17 08:06:40
Judged By
Score
0
Total Time
13ms
Peak Memory
772.0 KiB