結果

問題 No.884 Eat and Add
ユーザー tjaketjake
提出日時 2019-09-13 23:47:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 772 ms / 1,000 ms
コード長 567 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 286,836 KB
最終ジャッジ日時 2023-09-17 15:34:52
合計ジャッジ時間 6,524 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,156 KB
testcase_01 AC 72 ms
71,312 KB
testcase_02 AC 71 ms
71,284 KB
testcase_03 AC 772 ms
286,252 KB
testcase_04 AC 766 ms
286,392 KB
testcase_05 AC 765 ms
286,628 KB
testcase_06 AC 766 ms
286,560 KB
testcase_07 AC 430 ms
276,296 KB
testcase_08 AC 758 ms
286,836 KB
testcase_09 AC 769 ms
286,800 KB
testcase_10 AC 74 ms
71,332 KB
testcase_11 AC 74 ms
71,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
N = list(input())
ans = 0
cnt = 0
N.reverse()
n = len(N)
memo = [[-1, -1] for i in range(n)]
def dfs(i, b):
    if i == n:
        return b
    if memo[i][b] != -1:
        return memo[i][b]
    r = 10**6
    if N[i] == '1':
        if b:
            r = min(r, dfs(i+1, 1))
        else:
            r = min(r, min(dfs(i+1, 0), dfs(i+1, 1)) + 1)
    else:
        if b:
            r = min(r, min(dfs(i+1, 0), dfs(i+1, 1)) + 1)
        else:
            r = min(r, dfs(i+1, 0))
    memo[i][b] = r
    return r
print(dfs(0, 0))
0