結果

問題 No.783 門松計画
ユーザー titiatitia
提出日時 2024-02-03 03:20:16
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 66,152 KB
最終ジャッジ日時 2024-02-03 03:20:19
合計ジャッジ時間 2,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 42 ms
55,604 KB
testcase_02 WA -
testcase_03 AC 40 ms
55,604 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 38 ms
55,604 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 39 ms
55,604 KB
testcase_19 WA -
testcase_20 AC 41 ms
55,604 KB
testcase_21 AC 42 ms
55,604 KB
testcase_22 AC 47 ms
63,932 KB
testcase_23 AC 40 ms
55,604 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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(i+1,N):
            for k in range(j+1,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