結果

問題 No.3114 0→1
ユーザー Lim Hansen
提出日時 2025-04-20 00:38:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 560 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2025-04-20 00:38:46
合計ジャッジ時間 2,661 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def min_operations_to_good_string(n, s):
    operations = 0
    zero_count = 0
    one_count = 0

    for char in s:
        if char == '0':
            zero_count += 1
        else:
            one_count += 1
        
        # If 0s exceed 1s, we need to flip one 0 to 1
        if zero_count > one_count:
            operations += 1
            zero_count -= 1  # flip a 0 to 1
            one_count += 1

    print(operations)

# Reading input
if __name__ == "__main__":
    n = int(input())
    s = input().strip()
    min_operations_to_good_string(n, s)
0