結果
問題 | No.1238 選抜クラス |
ユーザー | None |
提出日時 | 2021-02-23 11:51:35 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,950 bytes |
コンパイル時間 | 1,587 ms |
コンパイル使用メモリ | 81,668 KB |
実行使用メモリ | 66,196 KB |
最終ジャッジ日時 | 2023-10-22 06:27:10 |
合計ジャッジ時間 | 5,388 ms |
ジャッジサーバーID (参考情報) |
judge9 / judge10 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,504 KB |
testcase_01 | AC | 37 ms
53,504 KB |
testcase_02 | AC | 44 ms
61,620 KB |
testcase_03 | AC | 40 ms
53,524 KB |
testcase_04 | AC | 38 ms
53,524 KB |
testcase_05 | AC | 37 ms
53,524 KB |
testcase_06 | AC | 37 ms
53,524 KB |
testcase_07 | AC | 40 ms
59,068 KB |
testcase_08 | AC | 50 ms
61,904 KB |
testcase_09 | AC | 46 ms
61,840 KB |
testcase_10 | AC | 40 ms
59,084 KB |
testcase_11 | AC | 54 ms
64,112 KB |
testcase_12 | AC | 46 ms
61,904 KB |
testcase_13 | AC | 47 ms
61,824 KB |
testcase_14 | AC | 50 ms
62,036 KB |
testcase_15 | AC | 61 ms
66,196 KB |
testcase_16 | AC | 51 ms
62,040 KB |
testcase_17 | TLE | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
ソースコード
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,item+1)+2)[::-1] else: S = range(min2(K,item+1)+2) 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[K][W]+dp[K][W+1] ########################################################## 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]) res=0 for K in range(1,N+1): W=M*K cnt=min_cost_with_num(single=True) res+=cnt res%=MOD print(res)