結果

問題 No.636 硬貨の枚数2
ユーザー titiatitia
提出日時 2021-12-12 00:38:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 375 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 10,852 KB
実行使用メモリ 18,096 KB
最終ジャッジ日時 2023-09-27 14:27:59
合計ジャッジ時間 5,193 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,680 KB
testcase_01 AC 20 ms
8,696 KB
testcase_02 AC 20 ms
8,732 KB
testcase_03 AC 20 ms
8,748 KB
testcase_04 AC 20 ms
8,636 KB
testcase_05 AC 20 ms
8,600 KB
testcase_06 AC 20 ms
8,640 KB
testcase_07 AC 20 ms
8,748 KB
testcase_08 AC 20 ms
8,632 KB
testcase_09 AC 21 ms
8,564 KB
testcase_10 AC 20 ms
8,620 KB
testcase_11 AC 20 ms
8,636 KB
testcase_12 AC 20 ms
8,636 KB
testcase_13 AC 20 ms
8,700 KB
testcase_14 AC 20 ms
8,736 KB
testcase_15 AC 20 ms
8,688 KB
testcase_16 AC 20 ms
8,632 KB
testcase_17 AC 20 ms
8,572 KB
testcase_18 AC 20 ms
8,636 KB
testcase_19 AC 20 ms
8,692 KB
testcase_20 AC 20 ms
8,704 KB
testcase_21 AC 20 ms
8,572 KB
testcase_22 AC 20 ms
8,672 KB
testcase_23 AC 20 ms
8,564 KB
testcase_24 AC 31 ms
11,864 KB
testcase_25 AC 45 ms
15,856 KB
testcase_26 AC 25 ms
10,024 KB
testcase_27 AC 32 ms
12,360 KB
testcase_28 AC 25 ms
10,016 KB
testcase_29 AC 46 ms
16,324 KB
testcase_30 AC 25 ms
9,732 KB
testcase_31 AC 39 ms
14,176 KB
testcase_32 AC 25 ms
10,184 KB
testcase_33 AC 24 ms
9,548 KB
testcase_34 AC 53 ms
17,896 KB
testcase_35 AC 53 ms
17,992 KB
testcase_36 AC 53 ms
17,988 KB
testcase_37 AC 53 ms
18,024 KB
testcase_38 AC 53 ms
17,956 KB
testcase_39 AC 53 ms
17,988 KB
testcase_40 AC 54 ms
18,072 KB
testcase_41 AC 53 ms
18,028 KB
testcase_42 AC 52 ms
18,036 KB
testcase_43 AC 53 ms
17,920 KB
testcase_44 AC 52 ms
17,908 KB
testcase_45 AC 52 ms
17,960 KB
testcase_46 AC 52 ms
17,992 KB
testcase_47 AC 53 ms
17,988 KB
testcase_48 AC 53 ms
18,044 KB
testcase_49 AC 53 ms
18,020 KB
testcase_50 AC 52 ms
18,096 KB
testcase_51 AC 53 ms
18,048 KB
testcase_52 AC 52 ms
17,924 KB
testcase_53 AC 52 ms
17,964 KB
testcase_54 AC 20 ms
8,600 KB
testcase_55 AC 20 ms
8,672 KB
testcase_56 AC 20 ms
8,636 KB
testcase_57 AC 20 ms
8,548 KB
testcase_58 AC 20 ms
8,716 KB
testcase_59 AC 20 ms
8,560 KB
testcase_60 AC 20 ms
8,692 KB
testcase_61 AC 20 ms
8,740 KB
testcase_62 AC 20 ms
8,612 KB
testcase_63 AC 20 ms
8,620 KB
testcase_64 AC 52 ms
17,740 KB
testcase_65 AC 52 ms
17,708 KB
testcase_66 AC 52 ms
17,588 KB
testcase_67 AC 52 ms
17,636 KB
testcase_68 AC 51 ms
17,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

N=input().strip()
LEN=len(N)

Y=[0,1,2,3,2,1,2,3,3,2,1]

from functools import lru_cache
@lru_cache(maxsize=None)
def calc(i,k):
    if i==-1:
        return k
    if k==0:
        x=int(N[i])
    else:
        x=int(N[i])+1

    ANS=min(Y[x]+calc(i-1,0),Y[10-x]+calc(i-1,1))

    return ANS
        


print(calc(LEN-1,0))
    
    
0