結果

問題 No.158 奇妙なお使い
ユーザー rlangevin
提出日時 2023-09-07 12:41:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,040 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 81,624 KB
実行使用メモリ 242,228 KB
最終ジャッジ日時 2024-06-25 06:46:00
合計ジャッジ時間 7,224 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 3 WA * 1 TLE * 1 -- * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

A = list(map(int, input().split()))
Db = int(input())
B = list(map(int, input().split()))
Dc = int(input())
C = list(map(int, input().split()))
num = [1000, 100, 1]
Sb, Sc = 0, 0
N = 0
for i in range(3):
    N += num[i] * A[i]
    Sb += num[i] * B[i]
    Sc += num[i] * C[i]

Edge1 = []
for a in range(11):
    now = num[0] * a
    if now > Db:
        break
    for b in range(101):
        now = num[0] * a + num[1] * b
        if now > Db:
            break
        c = Db - now
        if c < 0:
            break
        Edge1.append((a, b, c))
                

Edge2 = []
for a in range(11):
    now = num[0] * a
    if now > Dc:
        break
    for b in range(101):
        now = num[0] * a + num[1] * b
        if now > Dc:
            break
        c = Dc - now
        if c < 0:
            break
        Edge2.append((a, b, c))

L = [[] for i in range(N + 1)]
L[N].append(tuple(A))
inf = 10 ** 18
D = defaultdict(lambda: -inf)
D[tuple(A)] = 0
ans = 0
for i in range(N, -1, -1):
    for a1, b1, c1 in L[i]:
        for a2, b2, c2 in Edge1:
            if a1 < a2 or b1 < b2 or c1 < c2:
                continue
            temp = max(D[(a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])], D[(a1, b1, c1)] + 1)
            ans = max(ans, temp)
            if D[(a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])] != -inf:
                continue
            D[(a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2])] = temp
            L[i - Db + Sb].append((a1 - a2 + B[0], b1 - b2 + B[1], c1 - c2 + B[2]))

        for a2, b2, c2 in Edge2:
            if a1 < a2 or b1 < b2 or c1 < c2:
                continue
            temp = max(D[(a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])], D[(a1, b1, c1)] + 1)
            ans = max(ans, temp)
            if D[(a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])] != -inf:
                continue
            D[(a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2])] = temp
            L[i - Dc + Sc].append((a1 - a2 + C[0], b1 - b2 + C[1], c1 - c2 + C[2]))


print(ans)
0