結果

問題 No.1861 Required Number
ユーザー 👑 H20H20
提出日時 2022-03-04 23:11:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,153 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 84,732 KB
最終ジャッジ日時 2023-09-26 03:52:42
合計ジャッジ時間 7,514 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
75,724 KB
testcase_01 AC 99 ms
76,788 KB
testcase_02 AC 93 ms
71,620 KB
testcase_03 WA -
testcase_04 AC 100 ms
77,436 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 100 ms
76,956 KB
testcase_08 AC 109 ms
77,636 KB
testcase_09 AC 94 ms
77,052 KB
testcase_10 AC 104 ms
77,512 KB
testcase_11 AC 102 ms
77,144 KB
testcase_12 AC 96 ms
77,028 KB
testcase_13 AC 109 ms
77,456 KB
testcase_14 AC 101 ms
77,260 KB
testcase_15 AC 105 ms
77,208 KB
testcase_16 AC 94 ms
77,036 KB
testcase_17 AC 101 ms
77,292 KB
testcase_18 AC 105 ms
77,072 KB
testcase_19 AC 109 ms
77,572 KB
testcase_20 AC 110 ms
77,508 KB
testcase_21 AC 107 ms
77,644 KB
testcase_22 AC 112 ms
77,392 KB
testcase_23 AC 102 ms
77,172 KB
testcase_24 TLE -
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 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
04_evil_1.txt -- -
04_evil_2.txt -- -
04_evil_3.txt -- -
04_evil_4.txt -- -
権限があれば一括ダウンロードができます

ソースコード

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
minb = min(B)
CB = collections.Counter(B)
for k,v in CA.items():
    if k<minb:
        CB[k]+=v
for k,v in CB.items():
    if CB[k]==CA[k]:
        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