結果

問題 No.783 門松計画
ユーザー maspy
提出日時 2020-03-17 14:56:04
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 669 ms / 2,000 ms
コード長 1,203 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 44,552 KB
最終ジャッジ日時 2024-07-23 12:24:17
合計ジャッジ時間 16,784 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
import itertools

# %%
N, C = map(int, readline().split())
L = np.array(readline().split(), np.int32)
W = np.array(readline().split(), np.int32)


# %%
INF = 10 ** 4

# %%
dp = np.full((C + 1, N, N), -INF, np.int32)
for i, j in itertools.product(range(N), repeat=2):
    if L[i] == L[j]:
        continue
    cost = W[i] + W[j]
    if cost < C:
        dp[cost, i, j] = L[i] + L[j]


# %%
for c in range(1, C + 1):
    for k in range(N):
        newc = c + W[k]
        if newc > C:
            continue
        cond1 = (L != L[k])[:, None]
        cond2 = (L[:, None] < L[None, :]) & (L > L[k])[None, :]
        cond3 = (L[:, None] > L[None, :]) & (L < L[k])[None, :]
        cond = cond1 & (cond2 | cond3)
        add = L[k] - (~cond) * INF
        np.maximum(dp[newc][:, k], (dp[c] + add).max(axis=0), out=dp[newc][:, k])


# %%
for i, j in itertools.product(range(N), repeat=2):
    if L[i] == L[j]:
        continue
    cost = W[i] + W[j]
    if cost < C:
        dp[cost, i, j] = -INF


# %%
answer = max(0, dp.max())
print(answer)
0