結果

問題 No.636 硬貨の枚数2
ユーザー mkawa2mkawa2
提出日時 2021-12-05 18:11:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 986 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 8,428 KB
最終ジャッジ日時 2023-09-21 14:53:24
合計ジャッジ時間 4,015 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,276 KB
testcase_01 AC 16 ms
8,300 KB
testcase_02 AC 16 ms
8,220 KB
testcase_03 AC 15 ms
8,388 KB
testcase_04 AC 16 ms
8,348 KB
testcase_05 AC 16 ms
8,232 KB
testcase_06 AC 15 ms
8,220 KB
testcase_07 AC 15 ms
8,392 KB
testcase_08 AC 16 ms
8,300 KB
testcase_09 AC 16 ms
7,868 KB
testcase_10 AC 16 ms
8,280 KB
testcase_11 AC 16 ms
8,272 KB
testcase_12 AC 16 ms
8,280 KB
testcase_13 AC 16 ms
8,356 KB
testcase_14 AC 16 ms
8,300 KB
testcase_15 AC 15 ms
8,148 KB
testcase_16 AC 15 ms
8,292 KB
testcase_17 AC 16 ms
8,284 KB
testcase_18 AC 15 ms
8,264 KB
testcase_19 AC 16 ms
8,344 KB
testcase_20 AC 16 ms
8,292 KB
testcase_21 AC 15 ms
8,340 KB
testcase_22 AC 15 ms
8,288 KB
testcase_23 AC 15 ms
8,000 KB
testcase_24 AC 30 ms
7,728 KB
testcase_25 RE -
testcase_26 AC 20 ms
8,216 KB
testcase_27 AC 33 ms
7,884 KB
testcase_28 AC 20 ms
8,224 KB
testcase_29 RE -
testcase_30 AC 19 ms
8,220 KB
testcase_31 RE -
testcase_32 AC 20 ms
8,280 KB
testcase_33 AC 18 ms
8,216 KB
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 15 ms
8,228 KB
testcase_55 AC 16 ms
8,228 KB
testcase_56 AC 16 ms
8,344 KB
testcase_57 AC 16 ms
8,292 KB
testcase_58 AC 15 ms
8,228 KB
testcase_59 AC 16 ms
8,220 KB
testcase_60 AC 15 ms
8,224 KB
testcase_61 AC 16 ms
8,188 KB
testcase_62 AC 16 ms
8,192 KB
testcase_63 AC 16 ms
8,228 KB
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = 18446744073709551615
inf = 4294967295
md = 10**9+7
# md = 998244353

n = II()

def cost0(a):
    if a < 4: return a
    if a == 4: return 2
    return a-4

def cost1(a):
    if a > 6: return 10-a
    if a == 6: return 2
    return 6-a

c0, c1 = 0, inf
while n:
    n, a = divmod(n, 10)
    c0, c1 = min(cost0(a)+c0, cost0(a+1)+c1), min(cost1(a)+c0, cost1(a+1)+c1)
    # print(a, c0, c1)
print(min(c0, c1+1))
0