結果

問題 No.1457 ツブ消ししとるなHard
ユーザー titia
提出日時 2021-03-31 22:36:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 932 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 15,380 KB
最終ジャッジ日時 2024-12-15 20:30:37
合計ジャッジ時間 2,970 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

B=[]
C=[]

for a in A:
    if a>=X:
        C.append(a)
    elif a>Y:
        B.append(a)
        
if len(C)>M:
    print("Handicapped")
    exit()
    
B=sorted(B)
B=[b-Z for b in B]
C=[c-Z for c in C]
S=sum(C)


from collections import defaultdict
DP=defaultdict(int)
DP[(0,0)]=1
import copy

for b in B:
    NDP=copy.deepcopy(DP)

    for d,k in DP:
        if k+1<=M:
            NDP[(d+b,k+1)]+=DP[d,k]

    DP=NDP

ANS=0
for i,j in DP:
    if i==-S and j!=0:
        ANS+=DP[(i,j)]

print(ANS)





0