結果

問題 No.1861 Required Number
ユーザー 👑 KazunKazun
提出日時 2022-03-04 22:31:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 78,824 KB
最終ジャッジ日時 2023-09-26 03:46:45
合計ジャッジ時間 8,367 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,812 KB
testcase_01 AC 97 ms
76,560 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 207 ms
78,196 KB
testcase_05 WA -
testcase_06 AC 90 ms
71,680 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 95 ms
76,544 KB
testcase_10 AC 98 ms
76,724 KB
testcase_11 AC 96 ms
76,444 KB
testcase_12 AC 96 ms
76,632 KB
testcase_13 AC 96 ms
76,292 KB
testcase_14 AC 99 ms
76,308 KB
testcase_15 AC 97 ms
76,532 KB
testcase_16 AC 93 ms
76,452 KB
testcase_17 AC 96 ms
76,628 KB
testcase_18 AC 97 ms
76,608 KB
testcase_19 AC 99 ms
76,684 KB
testcase_20 AC 98 ms
76,612 KB
testcase_21 AC 97 ms
76,528 KB
testcase_22 AC 99 ms
76,432 KB
testcase_23 AC 96 ms
76,616 KB
testcase_24 AC 132 ms
78,000 KB
testcase_25 AC 167 ms
78,220 KB
testcase_26 AC 118 ms
77,996 KB
testcase_27 AC 129 ms
77,764 KB
testcase_28 AC 129 ms
78,100 KB
testcase_29 AC 125 ms
78,428 KB
testcase_30 AC 109 ms
78,040 KB
testcase_31 AC 166 ms
77,992 KB
testcase_32 AC 115 ms
78,108 KB
testcase_33 AC 146 ms
77,748 KB
testcase_34 AC 156 ms
78,284 KB
testcase_35 AC 158 ms
78,040 KB
testcase_36 AC 123 ms
77,696 KB
testcase_37 AC 128 ms
78,128 KB
testcase_38 AC 183 ms
78,824 KB
testcase_39 AC 133 ms
77,892 KB
testcase_40 AC 164 ms
78,140 KB
testcase_41 AC 191 ms
78,448 KB
testcase_42 AC 152 ms
78,004 KB
testcase_43 AC 132 ms
78,308 KB
testcase_44 WA -
04_evil_1.txt RE -
04_evil_2.txt RE -
04_evil_3.txt RE -
04_evil_4.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

def f(A):
    A=["*"]+A
    DP=[-1]*(K+1); DP[0]=0

    for i,a in enumerate(A[1:],1):
        for y in range(K,a-1,-1):
            if DP[y-a]>=0 and DP[y]==-1:
                DP[y]=i
    if DP[K]==-1:
        return None

    X=[]; x=K
    while x>0:
        X.append(DP[x])
        x-=A[DP[x]]
    return X
#==================================================
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

assert (N<=10**4) and (K<=10**3)

P=f(A)
if P==None:
    exit(print(-1))

Q=[N-k+1 for k in f(A[::-1])]

C=defaultdict(int)
for a in A:
    C[a]+=1

D=defaultdict(int)
for a in set(P)&set(Q):
    D[a]+=1

Ans=0
for a in C:
    if C[a]==D[a]:
        Ans+=C[a]

print(Ans)
0