結果

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

ソースコード

diff #

def min_operations_to_good_string(n, s):
    operations = 0
    balance = 0  # difference: ones - zeros

    for char in s:
        if char == '1':
            balance += 1
        else:  # char == '0'
            balance -= 1
        
        if balance < 0:
            operations += 1
            balance += 2  # we flip this '0' to '1', so net +2 to balance

    print(operations)

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