結果

問題 No.636 硬貨の枚数2
ユーザー vwxyzvwxyz
提出日時 2023-02-09 05:30:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,205 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 11,016 KB
実行使用メモリ 11,140 KB
最終ジャッジ日時 2023-09-20 17:05:46
合計ジャッジ時間 4,691 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,440 KB
testcase_01 AC 33 ms
10,348 KB
testcase_02 AC 33 ms
10,476 KB
testcase_03 AC 34 ms
10,436 KB
testcase_04 AC 33 ms
10,524 KB
testcase_05 AC 33 ms
10,424 KB
testcase_06 AC 33 ms
10,348 KB
testcase_07 AC 33 ms
10,368 KB
testcase_08 AC 34 ms
10,396 KB
testcase_09 AC 36 ms
10,476 KB
testcase_10 AC 33 ms
10,476 KB
testcase_11 AC 33 ms
10,404 KB
testcase_12 AC 33 ms
10,480 KB
testcase_13 AC 32 ms
10,468 KB
testcase_14 AC 33 ms
10,388 KB
testcase_15 AC 32 ms
10,404 KB
testcase_16 AC 33 ms
10,348 KB
testcase_17 AC 34 ms
10,392 KB
testcase_18 AC 32 ms
10,440 KB
testcase_19 AC 33 ms
10,356 KB
testcase_20 AC 33 ms
10,440 KB
testcase_21 AC 32 ms
10,360 KB
testcase_22 AC 33 ms
10,352 KB
testcase_23 AC 33 ms
10,420 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 AC 32 ms
10,460 KB
testcase_55 AC 33 ms
10,396 KB
testcase_56 AC 32 ms
10,444 KB
testcase_57 AC 32 ms
10,476 KB
testcase_58 AC 32 ms
10,500 KB
testcase_59 AC 32 ms
10,392 KB
testcase_60 AC 33 ms
10,480 KB
testcase_61 AC 32 ms
10,388 KB
testcase_62 AC 33 ms
10,496 KB
testcase_63 AC 32 ms
10,528 KB
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write

N=list(map(int,list(readline().rstrip())))
le=len(N)
inf=1<<60
cnt=[0,1,2,3,4,1,2,3,4,5,1]
@lru_cache(maxsize=None)
def solve(i,x):
    xx=x
    if i==0:
        retu=x
    else:
        n=N[i-1]+x
        x=n//10
        n%=10
        retu=inf
        retu=min(retu,solve(i-1,1+x)+cnt[10-n])
        if n<=5:
            retu=min(retu,solve(i-1,x)+1+cnt[5-n])
        retu=min(retu,solve(i-1,x)+cnt[n])
        if n>5:
            retu=min(retu,solve(i-1,x+1)+cnt[n-5]+1)
    return retu
ans=solve(le,0)
print(ans)
0