結果
| 問題 |
No.3114 0→1
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-20 04:13:02 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 758 bytes |
| コンパイル時間 | 664 ms |
| コンパイル使用メモリ | 12,288 KB |
| 実行使用メモリ | 32,268 KB |
| 最終ジャッジ日時 | 2025-04-20 04:13:09 |
| 合計ジャッジ時間 | 6,659 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | TLE * 1 -- * 29 |
ソースコード
def min_operations_to_make_good(s):
n = len(s)
arr = [int(c) for c in s]
changed = set()
for i in range(n-1):
balance = 0
zero_positions = []
for j in range(i, n):
if arr[j] == 0:
balance -= 1
zero_positions.append(j)
else:
balance += 1
if j > i and balance <= 0 and zero_positions:
pos = zero_positions[0]
zero_positions.pop(0)
if pos not in changed:
arr[pos] = 1
changed.add(pos)
balance += 2
return len(changed)
n = int(input())
s = input().strip()
print(min_operations_to_make_good(s))