/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 48ms 19.434 MiB
#2 Runtime Error list index out of range 55ms 25.195 MiB
#3 Runtime Error list index out of range 64ms 27.848 MiB

Code

import sys
import heapq

def main():
    try:
        input = sys.stdin.read
        data = input().split()
        index = 0
        testcases = int(data[index])
        index += 1
        results = []

        for _ in range(testcases):
            siz = int(data[index])
            ops = int(data[index + 1])
            word = data[index + 2]
            index += 3
            
            max_heap = []
            curr = 0
            
            for c in word:
                if c == '1':
                    curr += 1
                else:
                    if curr != 0:
                        heapq.heappush(max_heap, -curr)  # Use negative values for max heap
                    curr = 0
            
            if curr != 0:
                heapq.heappush(max_heap, -curr)
            
            while len(max_heap) > 1 and ops > 0:
                first = -heapq.heappop(max_heap)
                second = -heapq.heappop(max_heap) if max_heap else 0
                heapq.heappush(max_heap, -(first + second))
                ops -= 1
            
            results.append(str(-max_heap[0]))
        
        sys.stdout.write("\n".join(results) + "\n")
    except Exception as e:
        sys.stderr.write(str(e) + "\n")
        sys.exit(1)

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1159 Binary String
Contest
Brain Booster #8
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2025-02-17 14:58:24
Judged At
2025-02-17 14:58:24
Judged By
Score
0
Total Time
64ms
Peak Memory
27.848 MiB