結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,192 KB
testcase_01 AC 96 ms
168,916 KB
testcase_02 AC 91 ms
75,716 KB
testcase_03 WA -
testcase_04 AC 98 ms
81,724 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 101 ms
76,820 KB
testcase_08 AC 106 ms
77,156 KB
testcase_09 AC 98 ms
77,068 KB
testcase_10 AC 106 ms
77,332 KB
testcase_11 AC 104 ms
76,972 KB
testcase_12 AC 98 ms
77,036 KB
testcase_13 AC 106 ms
76,836 KB
testcase_14 AC 104 ms
76,836 KB
testcase_15 AC 105 ms
77,124 KB
testcase_16 AC 98 ms
76,572 KB
testcase_17 AC 106 ms
76,976 KB
testcase_18 AC 105 ms
76,912 KB
testcase_19 AC 106 ms
76,776 KB
testcase_20 AC 109 ms
77,268 KB
testcase_21 AC 104 ms
77,164 KB
testcase_22 AC 108 ms
77,192 KB
testcase_23 AC 103 ms
76,984 KB
testcase_24 AC 120 ms
78,492 KB
testcase_25 AC 136 ms
78,280 KB
testcase_26 AC 110 ms
77,832 KB
testcase_27 AC 117 ms
78,288 KB
testcase_28 AC 118 ms
78,144 KB
testcase_29 AC 113 ms
77,812 KB
testcase_30 AC 99 ms
77,376 KB
testcase_31 AC 133 ms
78,136 KB
testcase_32 AC 101 ms
77,192 KB
testcase_33 AC 127 ms
78,068 KB
testcase_34 AC 132 ms
78,256 KB
testcase_35 AC 134 ms
78,260 KB
testcase_36 AC 118 ms
77,996 KB
testcase_37 AC 126 ms
78,104 KB
testcase_38 AC 133 ms
78,272 KB
testcase_39 AC 123 ms
78,160 KB
testcase_40 AC 138 ms
78,324 KB
testcase_41 AC 135 ms
78,072 KB
testcase_42 AC 130 ms
78,440 KB
testcase_43 AC 119 ms
78,204 KB
testcase_44 AC 92 ms
71,452 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
L = []
B = []
while v>0:
    L.append(DP[v])
    B.append(A[DP[v]])
    v-=A[DP[v]]
ans = 0
CB = collections.Counter(B)
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