結果

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

ソースコード

diff #

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

    for i in range(n):
        if s[i] == '0':
            zero_count += 1
        else:
            one_count += 1

        if zero_count >= one_count:
            operations += 1
            zero_count -= 1
            one_count += 1

    return operations

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