結果

問題 No.158 奇妙なお使い
コンテスト
ユーザー cologne
提出日時 2026-01-30 15:56:03
言語 Python3
(3.14.2 + numpy 2.4.0 + scipy 1.16.3)
結果
AC  
実行時間 1,348 ms / 5,000 ms
コード長 1,406 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 626 ms
コンパイル使用メモリ 20,680 KB
実行使用メモリ 101,888 KB
最終ジャッジ日時 2026-01-30 15:56:14
合計ジャッジ時間 9,481 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys

sys.setrecursionlimit(10 ** 5)

from typing import List, Tuple


def int1(x: str, /): return int(x) - 1


def input(): return sys.stdin.readline().rstrip('\n')


def dbg(*args, **kwargs):
    print(*(repr(arg) for arg in args), *(f'{k}: {repr(v)}' for k, v in kwargs.items()), sep='; ', file=sys.stderr)


def main():
    a3, a2, a0 = map(int, input().split())
    db = int(input())
    b3, b2, b0 = map(int, input().split())
    dc = int(input())
    c3, c2, c0 = map(int, input().split())

    dp = {}

    def solve(v3, v2, v0):
        ret = dp.get((v3, v2, v0))
        if ret is not None:
            return ret
        ret = 0
        tb3 = min(db // 1000, v3)
        tb2 = min((db - tb3 * 1000) // 100, v2)
        tb0 = db - tb3 * 1000 - tb2 * 100
        if v0 >= tb0:
            ret = max(ret, 1 + solve(v3 - tb3 + b3, v2 - tb2 + b2, v0 - tb0 + b0))

        tc3 = min(dc // 1000, v3)
        tc2 = min((dc - tc3 * 1000) // 100, v2)
        tc0 = dc - tc3 * 1000 - tc2 * 100
        if v0 >= tc0:
            ret = max(ret, 1 + solve(v3 - tc3 + c3, v2 - tc2 + c2, v0 - tc0 + c0))
        dp[(v3, v2, v0)] = ret
        return ret

    return solve(a3, a2, a0)


def _start():
    ret = main()

    if ret is not None:
        if isinstance(ret, List) or isinstance(ret, Tuple):
            print(*ret)
        else:
            print(ret)


if __name__ == '__main__':
    _start()
0