結果

問題 No.825 賢いお買い物
ユーザー dango
提出日時 2023-06-24 17:56:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 82,852 KB
実行使用メモリ 59,136 KB
最終ジャッジ日時 2024-07-01 20:54:15
合計ジャッジ時間 2,390 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

a, b, c = map(int, input().split())
def f(rest, cost):
    i = 1
    while True:
        if i > cost:
            return float('inf')
        r2 = rest + (cost - i) // 10 + (cost - i) % 10
        if r2 == c:
            return i
        i += 1
def li(i, acc):
    def lj(j, acc):
        if j > a:
            return acc
        rest = f(b - i + a - j, i * 10 + j)
        return lj(j + 1, min(acc, rest))
    if i > b:
        return acc
    return li(i + 1, lj(0, acc))
if li(0, float('inf')) == float('inf'):
    print("Impossible")
else:
    print(li(0, float('inf')))
0