結果
| 問題 |
No.636 硬貨の枚数2
|
| コンテスト | |
| ユーザー |
mkawa2
|
| 提出日時 | 2023-07-13 22:17:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 187 ms / 2,000 ms |
| コード長 | 1,024 bytes |
| コンパイル時間 | 1,093 ms |
| コンパイル使用メモリ | 82,152 KB |
| 実行使用メモリ | 76,100 KB |
| 最終ジャッジ日時 | 2024-09-15 08:07:53 |
| 合計ジャッジ時間 | 8,953 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 65 |
ソースコード
import sys
sys.set_int_max_str_digits(1000005)
# 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))
mkawa2