Submission #66342558
Source Code Expand
Copy
T = int(input())for _ in range(T):n = int(input())s = input()total_ones = s.count('1')max_ending_here = 0max_so_far = 0for ch in s:if ch == '1':w = 1else:w = -1max_ending_here = max(w, max_ending_here + w)max_so_far = max(max_so_far, max_ending_here)best_gain = max_so_farif best_gain < 0:
T = int(input()) for _ in range(T): n = int(input()) s = input() total_ones = s.count('1') max_ending_here = 0 max_so_far = 0 for ch in s: if ch == '1': w = 1 else: w = -1 max_ending_here = max(w, max_ending_here + w) max_so_far = max(max_so_far, max_ending_here) best_gain = max_so_far if best_gain < 0: best_gain = 0 result = total_ones - best_gain print(result)
Submission Info
Submission Time | |
---|---|
Task | D - Flip to Gather |
User | kangping |
Language | Python (CPython 3.11.4) |
Score | 400 |
Code Size | 498 Byte |
Status | AC |
Exec Time | 150 ms |
Memory | 9284 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 10 ms | 8520 KiB |
00_sample_01.txt | AC | 10 ms | 8512 KiB |
01_test_00.txt | AC | 150 ms | 8428 KiB |
01_test_01.txt | AC | 141 ms | 8528 KiB |
01_test_02.txt | AC | 141 ms | 8464 KiB |
01_test_03.txt | AC | 142 ms | 8536 KiB |
01_test_04.txt | AC | 140 ms | 8576 KiB |
01_test_05.txt | AC | 142 ms | 8504 KiB |
01_test_06.txt | AC | 135 ms | 8428 KiB |
01_test_07.txt | AC | 135 ms | 8428 KiB |
01_test_08.txt | AC | 133 ms | 8476 KiB |
01_test_09.txt | AC | 114 ms | 8536 KiB |
01_test_10.txt | AC | 106 ms | 8416 KiB |
01_test_11.txt | AC | 98 ms | 8520 KiB |
01_test_12.txt | AC | 105 ms | 8536 KiB |
01_test_13.txt | AC | 92 ms | 8456 KiB |
01_test_14.txt | AC | 92 ms | 8596 KiB |
01_test_15.txt | AC | 87 ms | 8536 KiB |
01_test_16.txt | AC | 92 ms | 8484 KiB |
01_test_17.txt | AC | 94 ms | 8912 KiB |
01_test_18.txt | AC | 95 ms | 8480 KiB |
01_test_19.txt | AC | 90 ms | 9284 KiB |
01_test_20.txt | AC | 90 ms | 8960 KiB |
01_test_21.txt | AC | 102 ms | 9112 KiB |
01_test_22.txt | AC | 93 ms | 9216 KiB |
01_test_23.txt | AC | 93 ms | 9132 KiB |
01_test_24.txt | AC | 94 ms | 9232 KiB |
01_test_25.txt | AC | 96 ms | 9284 KiB |
01_test_26.txt | AC | 85 ms | 9208 KiB |
01_test_27.txt | AC | 85 ms | 9264 KiB |