結果
| 問題 | No.3114 0→1 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-20 12:48:49 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 260 ms / 2,000 ms |
| コード長 | 678 bytes |
| 記録 | |
| コンパイル時間 | 928 ms |
| コンパイル使用メモリ | 21,412 KB |
| 実行使用メモリ | 15,740 KB |
| 最終ジャッジ日時 | 2026-07-10 02:07:16 |
| 合計ジャッジ時間 | 8,967 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
import sys
input = sys.stdin.readline
def main():
N = int(input())
S = input().strip()
INF = 10**18
dp = {(1, 1): 0}
for c in S:
ndp = {}
for (l2, l1), cost in dp.items():
for out, add in ((0, 0), (1, 1)) if c == '0' else ((1, 0),):
if l1 == 0 and out == 0:
continue
if l2 == 0 and l1 == 1 and out == 0:
continue
nc = cost + add
key = (l1, out)
if nc < ndp.get(key, INF):
ndp[key] = nc
dp = ndp
ans = min(dp.values())
print(ans)
if __name__ == "__main__":
main()