結果

問題 No.158 奇妙なお使い
ユーザー rpy3cpprpy3cpp
提出日時 2015-06-02 17:31:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,618 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,776 KB
実行使用メモリ 29,440 KB
最終ジャッジ日時 2023-09-20 18:50:51
合計ジャッジ時間 15,669 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
8,056 KB
testcase_01 AC 306 ms
10,284 KB
testcase_02 AC 20 ms
8,128 KB
testcase_03 AC 16 ms
8,032 KB
testcase_04 RE -
testcase_05 AC 16 ms
8,176 KB
testcase_06 AC 16 ms
8,056 KB
testcase_07 AC 16 ms
8,144 KB
testcase_08 AC 19 ms
8,140 KB
testcase_09 AC 38 ms
8,116 KB
testcase_10 AC 41 ms
8,632 KB
testcase_11 AC 30 ms
8,636 KB
testcase_12 AC 19 ms
8,140 KB
testcase_13 AC 17 ms
8,204 KB
testcase_14 AC 152 ms
9,556 KB
testcase_15 AC 704 ms
12,916 KB
testcase_16 AC 489 ms
11,056 KB
testcase_17 WA -
testcase_18 RE -
testcase_19 AC 32 ms
8,444 KB
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 59 ms
8,604 KB
testcase_24 WA -
testcase_25 AC 17 ms
8,052 KB
testcase_26 AC 271 ms
9,580 KB
testcase_27 AC 19 ms
8,108 KB
testcase_28 AC 2,732 ms
17,188 KB
testcase_29 AC 25 ms
8,600 KB
testcase_30 AC 4,038 ms
29,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    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())
    return a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc


def solve(a3, a2, a1, b3, b2, b1, c3, c2, c1, db, dc):
    memo = dict()
    dif_b = db - b3*1000 - b2*100 - b1
    dif_c = dc - c3*1000 - c2*100 - c1
    dif = min(dif_b, dif_c)
    record = 0

    def dfs(a3, a2, a1, depth):
        nonlocal record
        nonlocal memo
        if (a3, a2, a1) in memo:
            return memo[a3, a2, a1]
        if (a3 * 1000 + a2 * 100 + a1) // dif <= record - depth:
            return 0
        tmp = 0
        for d3, d2, d1 in generate_payment_patterns(a3, a2, a1, db):
            t = dfs(a3-d3+b3, a2-d2+b2, a1-d1+b1, depth+1)
            if t > tmp:
                tmp = t
        for d3, d2, d1 in generate_payment_patterns(a3, a2, a1, dc):
            t = dfs(a3-d3+c3, a2-d2+c2, a1-d1+c1, depth+1)
            if t > tmp:
                tmp = t
        memo[a3, a2, a1] = tmp
        if depth + tmp > record:
            record = depth + tmp
        return tmp

    dfs(a3, a2, a1, 0)
    return record


def generate_payment_patterns(a3, a2, a1, d):
    for d3 in range(0, d+1, 1000):
        if d3//1000 > a3:
            break
        for d2 in range(0, d - d3 + 1, 100):
            if d2//100 > a2:
                break
            d1 = d - d3 - d2
            if d1 > a1:
                continue
            yield d3//1000, d2//100, d1


if __name__ == '__main__':
    param = read_data()
    print(solve(*param))
0