結果

問題 No.783 門松計画
ユーザー rlangevinrlangevin
提出日時 2023-10-12 12:07:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 1,119 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 86,860 KB
実行使用メモリ 79,680 KB
最終ジャッジ日時 2023-10-12 12:07:28
合計ジャッジ時間 5,425 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
76,436 KB
testcase_01 AC 82 ms
76,444 KB
testcase_02 AC 81 ms
76,284 KB
testcase_03 AC 79 ms
75,804 KB
testcase_04 AC 81 ms
75,832 KB
testcase_05 AC 78 ms
76,156 KB
testcase_06 AC 78 ms
75,620 KB
testcase_07 AC 78 ms
75,684 KB
testcase_08 AC 76 ms
75,560 KB
testcase_09 AC 79 ms
75,900 KB
testcase_10 AC 175 ms
79,412 KB
testcase_11 AC 317 ms
79,432 KB
testcase_12 AC 216 ms
79,680 KB
testcase_13 AC 142 ms
79,196 KB
testcase_14 AC 157 ms
79,428 KB
testcase_15 AC 121 ms
78,056 KB
testcase_16 AC 102 ms
76,888 KB
testcase_17 AC 125 ms
78,644 KB
testcase_18 AC 82 ms
76,220 KB
testcase_19 AC 143 ms
79,236 KB
testcase_20 AC 79 ms
75,880 KB
testcase_21 AC 94 ms
76,296 KB
testcase_22 AC 98 ms
76,568 KB
testcase_23 AC 76 ms
76,228 KB
testcase_24 AC 141 ms
78,660 KB
testcase_25 AC 119 ms
78,004 KB
testcase_26 AC 146 ms
79,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def kadomatsu(a, b, c):
    if a == b or b == c or c == a:
        return False
    if a < b < c or a > b > c:
        return False
    return True

N, C = map(int, input().split())
L = list(map(int, input().split()))
W = list(map(int, input().split()))
M = 50
ans = 0
inf = 10 ** 18
dp = [[[-inf] * (M + 1) for i in range(M + 1)] for j in range(C + 1)] 
for i in range(N):
    for j in range(N):
        for k in range(N):
            if not kadomatsu(L[i], L[j], L[k]):
                continue
            if W[i] + W[j] + W[k] > C:
                continue
            dp[W[i] + W[j] + W[k]][L[j]][L[k]] = max(dp[W[i] + W[j] + W[k]][L[j]][L[k]], L[i] + L[j] + L[k])

for c in range(C + 1):
    for a in range(M + 1):
        for b in range(M + 1):
            if dp[c][a][b] == -inf:
                continue
            for i in range(N):
                if not kadomatsu(a, b, L[i]):
                    continue
                if c + W[i] > C:
                    continue
                dp[c + W[i]][b][L[i]] = max(dp[c + W[i]][b][L[i]], dp[c][a][b] + L[i])
            ans = max(ans, dp[c][a][b])

print(ans)
0