結果
| 問題 |
No.3114 0→1
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-20 17:06:45 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 759 bytes |
| コンパイル時間 | 262 ms |
| コンパイル使用メモリ | 12,032 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2025-04-20 17:06:54 |
| 合計ジャッジ時間 | 2,970 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | WA * 30 |
ソースコード
def min_operations_to_good_string(N, S):
# 0を1に変更する必要がある回数をカウント
zero_count = 0 # 連続した0の数
ones_count = 0 # 1の数
operations = 0 # 操作回数
for i in range(N):
if S[i] == '0':
zero_count += 1
else:
ones_count += 1
# 0の数が1の数を超えた場合、その差だけ0を1に変える
if zero_count > ones_count:
operations += zero_count - ones_count
zero_count = ones_count # 差を解消し、0の数を1の数に合わせる
return operations
# 入力の処理
N = int(input())
S = input().strip()
# 最小操作回数を求める
print(min_operations_to_good_string(N, S))