結果

問題 No.636 硬貨の枚数2
ユーザー vwxyzvwxyz
提出日時 2023-02-09 05:28:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,201 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 11,196 KB
最終ジャッジ日時 2023-09-20 17:04:26
合計ジャッジ時間 5,651 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,436 KB
testcase_01 AC 36 ms
10,296 KB
testcase_02 AC 33 ms
10,348 KB
testcase_03 AC 33 ms
10,444 KB
testcase_04 WA -
testcase_05 AC 34 ms
10,380 KB
testcase_06 WA -
testcase_07 AC 34 ms
10,420 KB
testcase_08 AC 34 ms
10,396 KB
testcase_09 WA -
testcase_10 AC 33 ms
10,336 KB
testcase_11 AC 33 ms
10,292 KB
testcase_12 AC 33 ms
10,348 KB
testcase_13 WA -
testcase_14 AC 33 ms
10,428 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 33 ms
10,368 KB
testcase_22 WA -
testcase_23 WA -
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 33 ms
10,368 KB
testcase_55 AC 33 ms
10,428 KB
testcase_56 AC 34 ms
10,428 KB
testcase_57 AC 33 ms
10,368 KB
testcase_58 AC 34 ms
10,352 KB
testcase_59 AC 33 ms
10,344 KB
testcase_60 AC 33 ms
10,364 KB
testcase_61 AC 33 ms
10,412 KB
testcase_62 WA -
testcase_63 AC 32 ms
10,452 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)+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