結果

問題 No.783 門松計画
ユーザー maspymaspy
提出日時 2020-03-17 14:56:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,203 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 11,140 KB
実行使用メモリ 30,304 KB
最終ジャッジ日時 2023-09-30 18:45:20
合計ジャッジ時間 5,600 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
29,884 KB
testcase_01 AC 142 ms
29,812 KB
testcase_02 AC 142 ms
29,944 KB
testcase_03 AC 137 ms
29,772 KB
testcase_04 AC 139 ms
29,876 KB
testcase_05 AC 137 ms
29,860 KB
testcase_06 AC 137 ms
29,944 KB
testcase_07 AC 137 ms
29,880 KB
testcase_08 AC 139 ms
29,824 KB
testcase_09 AC 137 ms
29,840 KB
testcase_10 AC 214 ms
30,188 KB
testcase_11 AC 268 ms
30,304 KB
testcase_12 AC 242 ms
30,260 KB
testcase_13 AC 167 ms
29,984 KB
testcase_14 AC 182 ms
30,172 KB
testcase_15 AC 155 ms
30,044 KB
testcase_16 AC 141 ms
29,940 KB
testcase_17 AC 152 ms
29,952 KB
testcase_18 AC 138 ms
29,912 KB
testcase_19 AC 166 ms
30,188 KB
testcase_20 AC 137 ms
29,884 KB
testcase_21 AC 136 ms
29,892 KB
testcase_22 AC 142 ms
29,944 KB
testcase_23 AC 138 ms
29,832 KB
testcase_24 AC 156 ms
30,080 KB
testcase_25 AC 146 ms
29,980 KB
testcase_26 AC 159 ms
30,004 KB
権限があれば一括ダウンロードができます

ソースコード

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