結果

問題 No.884 Eat and Add
ユーザー tjaketjake
提出日時 2019-09-13 23:50:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 424 ms / 1,000 ms
コード長 569 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 10,768 KB
実行使用メモリ 68,292 KB
最終ジャッジ日時 2023-09-17 15:35:27
合計ジャッジ時間 3,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,820 KB
testcase_01 AC 16 ms
7,804 KB
testcase_02 AC 16 ms
7,896 KB
testcase_03 AC 424 ms
68,184 KB
testcase_04 AC 417 ms
68,288 KB
testcase_05 AC 415 ms
68,292 KB
testcase_06 AC 410 ms
68,224 KB
testcase_07 AC 232 ms
68,228 KB
testcase_08 AC 410 ms
68,140 KB
testcase_09 AC 419 ms
68,212 KB
testcase_10 AC 16 ms
7,784 KB
testcase_11 AC 16 ms
7,936 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