結果
問題 |
No.3114 0→1
|
ユーザー |
|
提出日時 | 2025-04-20 04:54:20 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 865 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2025-04-20 04:54:23 |
合計ジャッジ時間 | 2,953 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | WA * 30 |
ソースコード
def min_operations_to_good_string(S): N = len(S) ones = S.count('1') zero_blocks = [] i = 0 while i < N: if S[i] == '0': start = i while i < N and S[i] == '0': i += 1 length = i - start if length >= 2: zero_blocks.append(length) else: i += 1 total_zeros_in_blocks = sum(zero_blocks) if total_zeros_in_blocks < ones: return 0 zero_blocks.sort(reverse=True) ops = 0 for block in zero_blocks: for _ in range(block): total_zeros_in_blocks -= 1 ops += 1 ones += 1 if total_zeros_in_blocks < ones: return ops return ops if __name__ == "__main__": N = int(input()) S = input().strip() print(min_operations_to_good_string(S))