結果

問題 No.1238 選抜クラス
ユーザー NoneNone
提出日時 2021-02-23 12:07:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 1,979 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 81,904 KB
実行使用メモリ 111,948 KB
最終ジャッジ日時 2023-10-22 06:43:57
合計ジャッジ時間 9,117 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
59,816 KB
testcase_01 AC 46 ms
59,816 KB
testcase_02 AC 48 ms
62,072 KB
testcase_03 AC 44 ms
59,664 KB
testcase_04 AC 44 ms
59,664 KB
testcase_05 AC 42 ms
59,600 KB
testcase_06 AC 43 ms
59,664 KB
testcase_07 AC 47 ms
61,864 KB
testcase_08 AC 49 ms
62,072 KB
testcase_09 AC 50 ms
62,072 KB
testcase_10 AC 46 ms
61,864 KB
testcase_11 AC 51 ms
62,072 KB
testcase_12 AC 50 ms
62,072 KB
testcase_13 AC 52 ms
62,072 KB
testcase_14 AC 50 ms
62,072 KB
testcase_15 AC 52 ms
62,072 KB
testcase_16 AC 51 ms
62,072 KB
testcase_17 AC 498 ms
111,948 KB
testcase_18 AC 441 ms
105,216 KB
testcase_19 AC 449 ms
105,576 KB
testcase_20 AC 424 ms
103,644 KB
testcase_21 AC 358 ms
92,592 KB
testcase_22 AC 325 ms
83,688 KB
testcase_23 AC 323 ms
83,612 KB
testcase_24 AC 335 ms
83,772 KB
testcase_25 AC 325 ms
83,760 KB
testcase_26 AC 465 ms
111,352 KB
testcase_27 AC 434 ms
104,768 KB
testcase_28 AC 473 ms
104,672 KB
testcase_29 AC 429 ms
98,212 KB
testcase_30 AC 66 ms
64,340 KB
testcase_31 AC 114 ms
66,388 KB
testcase_32 AC 222 ms
82,500 KB
testcase_33 AC 46 ms
59,636 KB
testcase_34 AC 295 ms
87,028 KB
testcase_35 AC 78 ms
64,340 KB
testcase_36 AC 54 ms
62,088 KB
testcase_37 AC 71 ms
64,340 KB
testcase_38 AC 394 ms
97,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def min_cost_with_num(single=False,INF=float("inf")):
    """
    :param larger_num:     False = (個数 = K)の時の最小価値
                           True  = (個数 >= K)の時の最小価値
    :param larger_weight:  False = (重さ = W)の時の最小価値
                           True  = (重さ >= W)の時の最小価値
    :param single:         False = 重複あり

    dp[num (<=K)][weight (<=W)] = 個数と重さを固定した時の最小価値
    """
    dp_max = 0   # 総和価値の最大値
    dp = [[dp_max]*(W+2) for _ in range(K+2)]
    dp[0][0] = 1   # 重さ 0 の時は価値 0

    for item in range(N):
        if single:
            S = range(min2(K+1,item+1)+1)[::-1]
        else:
            S = range(min2(K+1,item+1)+1)
        for num in S:
            if num==0:
                dp[min2(num+1,K+1)][min2(weight_list[item],W+1)]+=dp[0][0]
            else:
                for weight in range(W+2):
                    if dp[num][weight]!=dp_max:
                        dp[min2(num+1,K+1)][min2(weight+weight_list[item],W+1)]+=dp[num][weight]
    return dp

##########################################################
def max2(x,y):
    return x if x > y else y

def min2(x,y):
    return x if x < y else y
##########################################################
def example():
    global input
    example = iter(
        """
2 2
1 3




        """
            .strip().split("\n"))
    input = lambda: next(example)
##########################################################
import sys
from bisect import *
input = sys.stdin.readline

# example()
MOD=10**9+7

N,M=map(int, input().split())
A=list(map(int, input().split()))

weight_list = []
for i in range(N):
    """ cost と weight が逆転して入力されている場合有り """
    weight_list.append(A[i])

W=10**4+10
K=N
dp=min_cost_with_num(single=True)
res=0
for k in range(1,N+1):
    for w in range(M*k,W+2):
        res+=dp[k][w]
        res%=MOD
print(res)
0