/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 14ms 3.094 MiB
#2 Wrong Answer 38ms 4.273 MiB
#3 Wrong Answer 44ms 4.465 MiB

Code

import sys

def main():
    input = sys.stdin.read().split()
    idx = 0
    T = int(input[idx])
    idx += 1
    for _ in range(T):
        N, K = int(input[idx]), int(input[idx+1])
        idx += 2
        S = input[idx]
        idx += 1
        
        # Split into runs
        runs = []
        if N == 0:
            print(0)
            continue
        prev = S[0]
        count = 1
        for c in S[1:]:
            if c == prev:
                count += 1
            else:
                runs.append((prev, count))
                prev = c
                count = 1
        runs.append((prev, count))
        
        # Extract 1s groups
        ones = [length for char, length in runs if char == '1']
        if not ones:
            print(0)
            continue
        m = len(ones)
        B = m - 1
        if K >= B:
            print(sum(ones))
        else:
            window_size = K + 1
            current_sum = sum(ones[:window_size])
            max_sum = current_sum
            for i in range(window_size, m):
                current_sum += ones[i] - ones[i - window_size]
                if current_sum > max_sum:
                    max_sum = current_sum
            print(max_sum)
            
if __name__ == '__main__':
    main()

Information

Submit By
Type
Submission
Problem
P1159 Binary String
Contest
Brain Booster #8
Language
Python 3 (Python 3.12.3)
Submit At
2025-02-17 15:37:10
Judged At
2025-02-17 15:37:10
Judged By
Score
0
Total Time
44ms
Peak Memory
4.465 MiB