結果

問題 No.636 硬貨の枚数2
ユーザー mkawa2
提出日時 2021-12-05 18:11:04
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 986 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-07 08:39:38
合計ジャッジ時間 3,825 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 37 RE * 28
権限があれば一括ダウンロードができます

ソースコード

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