結果

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

ソースコード

diff #

def min_operations_to_good_string(n, s):
    operations = 0
    i = 0

    while i < n - 1:
        # Only start checking if current char is '0'
        if s[i] == '0':
            count_0 = 1
            count_1 = 0
            j = i + 1

            while j < n:
                if s[j] == '0':
                    count_0 += 1
                else:
                    count_1 += 1

                if count_0 > count_1:
                    operations += 1
                    i = j + 1  # Skip over the violated segment
                    break
                j += 1
            else:
                break  # No further violations
        else:
            i += 1

    print(operations)

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