結果

問題 No.825 賢いお買い物
ユーザー dangodango
提出日時 2023-06-24 17:56:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 86,864 KB
実行使用メモリ 75,920 KB
最終ジャッジ日時 2023-09-14 13:32:03
合計ジャッジ時間 3,594 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
75,400 KB
testcase_01 AC 81 ms
75,344 KB
testcase_02 AC 79 ms
75,292 KB
testcase_03 AC 79 ms
75,308 KB
testcase_04 AC 79 ms
75,468 KB
testcase_05 AC 78 ms
75,332 KB
testcase_06 AC 72 ms
70,956 KB
testcase_07 AC 78 ms
75,076 KB
testcase_08 AC 79 ms
75,736 KB
testcase_09 AC 76 ms
71,192 KB
testcase_10 AC 79 ms
75,172 KB
testcase_11 AC 80 ms
75,868 KB
testcase_12 AC 80 ms
75,348 KB
testcase_13 AC 74 ms
71,292 KB
testcase_14 AC 78 ms
75,256 KB
testcase_15 AC 80 ms
75,872 KB
testcase_16 AC 80 ms
75,920 KB
testcase_17 AC 79 ms
75,360 KB
testcase_18 AC 80 ms
75,896 KB
testcase_19 AC 79 ms
75,316 KB
testcase_20 AC 77 ms
75,396 KB
testcase_21 AC 74 ms
71,064 KB
権限があれば一括ダウンロードができます

ソースコード

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