結果

問題 No.636 硬貨の枚数2
ユーザー maspy
提出日時 2020-03-24 03:18:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 384 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-12-30 10:15:51
合計ジャッジ時間 4,971 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 65
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = tuple(map(int, read().decode().rstrip()))

dp = (0, 1)
INF = 10 ** 9
A = [0, 1, 2, 3, 2, 1, 2, 3, 3, 2, 1]
for n in N:
    x = min(dp[0] + A[n], dp[1] + A[10 - n])
    y = min(dp[0] + A[n + 1], dp[1] + A[9 - n])
    dp = (x, y)
print(dp[0])
0