結果

問題 No.884 Eat and Add
ユーザー rlangevinrlangevin
提出日時 2023-08-30 12:20:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 1,000 ms
コード長 384 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 89,244 KB
最終ジャッジ日時 2023-08-30 12:20:14
合計ジャッジ時間 3,220 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,176 KB
testcase_01 AC 76 ms
71,472 KB
testcase_02 AC 77 ms
71,256 KB
testcase_03 AC 111 ms
89,244 KB
testcase_04 AC 110 ms
89,000 KB
testcase_05 AC 109 ms
89,000 KB
testcase_06 AC 109 ms
89,108 KB
testcase_07 AC 92 ms
82,532 KB
testcase_08 AC 92 ms
82,688 KB
testcase_09 AC 105 ms
89,084 KB
testcase_10 AC 76 ms
71,260 KB
testcase_11 AC 78 ms
71,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = list(input())
inf = 10 ** 18
dp0 = [inf] * (len(N) + 1)
dp1 = [inf] * (len(N) + 1)
dp0[0], dp1[0] = 0, 1
for i, n in enumerate(N, 1):
    if n == "0":
        dp0[i] = min(dp0[i], dp0[i - 1])
        dp1[i] = min(dp1[i], dp1[i - 1] + 1, dp0[i - 1] + 1)
    else:
        dp0[i] = min(dp0[i], dp0[i - 1] + 1, dp1[i - 1] + 1)
        dp1[i] = min(dp1[i], dp1[i - 1])

print(dp0[-1])
0