結果

問題 No.783 門松計画
ユーザー titiatitia
提出日時 2024-02-03 03:20:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,480 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 126,424 KB
最終ジャッジ日時 2024-02-03 03:20:58
合計ジャッジ時間 4,949 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,604 KB
testcase_01 AC 37 ms
55,476 KB
testcase_02 AC 38 ms
55,604 KB
testcase_03 AC 37 ms
55,476 KB
testcase_04 AC 38 ms
55,604 KB
testcase_05 AC 37 ms
55,604 KB
testcase_06 AC 39 ms
55,604 KB
testcase_07 AC 37 ms
55,604 KB
testcase_08 AC 37 ms
55,476 KB
testcase_09 AC 38 ms
55,604 KB
testcase_10 AC 307 ms
83,276 KB
testcase_11 AC 1,480 ms
126,424 KB
testcase_12 AC 534 ms
97,148 KB
testcase_13 AC 190 ms
80,708 KB
testcase_14 AC 121 ms
78,288 KB
testcase_15 AC 62 ms
68,364 KB
testcase_16 AC 49 ms
64,048 KB
testcase_17 AC 61 ms
72,764 KB
testcase_18 AC 38 ms
55,604 KB
testcase_19 AC 90 ms
76,748 KB
testcase_20 AC 37 ms
55,604 KB
testcase_21 AC 46 ms
64,044 KB
testcase_22 AC 46 ms
64,048 KB
testcase_23 AC 45 ms
55,604 KB
testcase_24 AC 97 ms
76,848 KB
testcase_25 AC 54 ms
68,364 KB
testcase_26 AC 99 ms
77,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,C=map(int,input().split())
L=list(map(int,input().split()))
W=list(map(int,input().split()))

from functools import lru_cache
@lru_cache(maxsize=None)
def calc(a,b,cost):
    ANS=0
    if a==b==0:
        for i in range(N):
            if W[i]<=cost:
                ANS=max(ANS,L[i]+calc(0,L[i],cost-W[i]))

        return ANS

    if a==0:
        for i in range(N):
            if L[i]!=b and W[i]<=cost:
                ANS=max(ANS,L[i]+calc(b,L[i],cost-W[i]))

        return ANS

    if a<b:
        for i in range(N):
            if W[i]<=cost and L[i]<b and L[i]!=a:
                ANS=max(ANS,L[i]+calc(b,L[i],cost-W[i]))
        return ANS
    else:
        for i in range(N):
            if W[i]<=cost and L[i]>b and L[i]!=a:
                ANS=max(ANS,L[i]+calc(b,L[i],cost-W[i]))
        return ANS

if len(set(sorted(L)))<=2:
    print(0)
else:
    ANS=0

    for i in range(N):
        for j in range(N):
            for k in range(N):
                if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i] and W[i]+W[j]+W[k]<=C:
                    if L[i]<L[j] and L[j]>L[k]:
                        ANS=max(ANS,L[i]+L[j]+L[k]+calc(L[j],L[k],C-W[i]-W[j]-W[k]))
                        
                    if L[i]>L[j] and L[j]<L[k]:
                        ANS=max(ANS,L[i]+L[j]+L[k]+calc(L[j],L[k],C-W[i]-W[j]-W[k]))

    print(ANS)
0