結果

問題 No.1861 Required Number
ユーザー 👑 H20H20
提出日時 2022-03-04 23:04:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,003 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 170,944 KB
最終ジャッジ日時 2023-09-26 03:52:05
合計ジャッジ時間 22,064 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
163,952 KB
testcase_01 AC 98 ms
81,112 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 100 ms
81,868 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 108 ms
77,632 KB
testcase_09 AC 93 ms
76,736 KB
testcase_10 AC 106 ms
77,288 KB
testcase_11 AC 101 ms
76,864 KB
testcase_12 AC 96 ms
76,724 KB
testcase_13 AC 107 ms
77,160 KB
testcase_14 AC 104 ms
77,164 KB
testcase_15 AC 104 ms
77,052 KB
testcase_16 AC 99 ms
76,852 KB
testcase_17 AC 107 ms
76,984 KB
testcase_18 AC 106 ms
77,232 KB
testcase_19 AC 107 ms
77,216 KB
testcase_20 AC 109 ms
76,888 KB
testcase_21 AC 104 ms
77,236 KB
testcase_22 AC 109 ms
77,276 KB
testcase_23 AC 103 ms
77,164 KB
testcase_24 AC 142 ms
78,200 KB
testcase_25 AC 216 ms
78,532 KB
testcase_26 AC 132 ms
78,416 KB
testcase_27 AC 133 ms
78,212 KB
testcase_28 AC 160 ms
78,188 KB
testcase_29 AC 142 ms
78,432 KB
testcase_30 AC 99 ms
77,376 KB
testcase_31 AC 174 ms
78,328 KB
testcase_32 AC 107 ms
77,352 KB
testcase_33 AC 156 ms
78,224 KB
testcase_34 AC 199 ms
78,312 KB
testcase_35 AC 205 ms
78,420 KB
testcase_36 AC 144 ms
78,480 KB
testcase_37 AC 153 ms
78,356 KB
testcase_38 AC 201 ms
78,444 KB
testcase_39 AC 169 ms
78,344 KB
testcase_40 AC 177 ms
78,168 KB
testcase_41 AC 208 ms
78,540 KB
testcase_42 AC 193 ms
78,428 KB
testcase_43 AC 134 ms
78,156 KB
testcase_44 AC 92 ms
71,760 KB
04_evil_1.txt TLE -
04_evil_2.txt TLE -
04_evil_3.txt TLE -
04_evil_4.txt TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

N,K = map(int,input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
CA = collections.Counter(A)
if sum(A)==K:
    print(N)
    exit()
if CA[1]>K:
    print(0)
    exit()

DP = [-1]*(K+1)
for i in range(N):
    for j in reversed(range(K)):
        if DP[j]!=-1 and j+A[i]<=K and DP[j+A[i]]==-1:
            DP[j+A[i]]=i
        else:
            pass
    if DP[K]!=-1:
        break
    if DP[A[i]]==-1:
        DP[A[i]]=i
if DP[K]==-1:
    print(-1)
    exit()
v = K
B = []
while v>0:
    B.append(A[DP[v]])
    v-=A[DP[v]]
ans = 0
CB = collections.Counter(B)
for k,v in CB.items():
    DP = [-1]*(K+1)
    for i in range(N):
        if A[i]==k:
            continue
        for j in reversed(range(K)):
            if DP[j]!=-1 and j+A[i]<=K and DP[j+A[i]]==-1:
                DP[j+A[i]]=i
            else:
                pass
        if DP[K]!=-1:
            break
        if DP[A[i]]==-1:
            DP[A[i]]=i
    if DP[K]==-1:
        ans+=v

print(ans)
0