結果

問題 No.158 奇妙なお使い
ユーザー rpy3cpp
提出日時 2015-06-02 19:39:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 2,151 ms / 5,000 ms
コード長 698 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 88,520 KB
最終ジャッジ日時 2024-06-29 02:03:02
合計ジャッジ時間 4,623 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
a3, a2, a1 = map(int, input().split())
db = int(input())
b3, b2, b1 = map(int, input().split())
dc = int(input())
c3, c2, c1 = map(int, input().split())
m = dict()
def g(a3, a2, a1, b3, b2, b1, d):
    for d3 in range(min(d//1000, a3), -1, -1):
        for d2 in range(min((d - d3*1000)//100,a2), -1, -1):
            d1 = d - d3*1000 - d2*100
            if d1 > a1:continue
            return dfs(a3-d3+b3, a2-d2+b2, a1-d1+b1) + 1
    return 0
def dfs(a3, a2, a1):
    global m
    if (a3, a2, a1) in m: return m[a3, a2, a1]
    t = max(g(a3, a2, a1, b3, b2, b1, db), g(a3, a2, a1, c3, c2, c1, dc))
    m[a3, a2, a1] = t
    return t
print(dfs(a3, a2, a1))
0