結果

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

ソースコード

diff #

def min_operations_to_good_string(S):
    ones = S.count('1')
    operations = 0
    
    while True:
        i = 0
        found_bad_sequence = False
        
        while i < len(S):
            if S[i] == '0':
                start = i
                while i < len(S) and S[i] == '0':
                    i += 1
                length = i - start
                
                if length >= 2 and length >= ones:
                    found_bad_sequence = True
                    mid = start + length // 2
                    S = S[:mid] + '1' + S[mid+1:]
                    ones += 1
                    operations += 1
                    break
            else:
                i += 1
        
        if not found_bad_sequence:
            break
    
    return operations

if __name__ == "__main__":
    N = int(input())
    S = input().strip()
    print(min_operations_to_good_string(S))
0