結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
163,612 KB
testcase_01 AC 104 ms
84,120 KB
testcase_02 AC 92 ms
75,800 KB
testcase_03 WA -
testcase_04 AC 101 ms
81,784 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 100 ms
76,820 KB
testcase_08 AC 103 ms
76,700 KB
testcase_09 AC 96 ms
76,800 KB
testcase_10 AC 106 ms
77,292 KB
testcase_11 AC 102 ms
77,240 KB
testcase_12 AC 98 ms
76,748 KB
testcase_13 AC 105 ms
77,036 KB
testcase_14 AC 104 ms
76,820 KB
testcase_15 AC 103 ms
76,720 KB
testcase_16 AC 97 ms
76,632 KB
testcase_17 AC 103 ms
77,248 KB
testcase_18 AC 104 ms
77,124 KB
testcase_19 AC 103 ms
77,172 KB
testcase_20 AC 109 ms
77,216 KB
testcase_21 AC 103 ms
76,860 KB
testcase_22 AC 109 ms
77,068 KB
testcase_23 AC 102 ms
77,264 KB
testcase_24 AC 116 ms
78,092 KB
testcase_25 AC 132 ms
78,148 KB
testcase_26 AC 108 ms
77,816 KB
testcase_27 AC 115 ms
77,924 KB
testcase_28 AC 115 ms
77,928 KB
testcase_29 AC 112 ms
77,796 KB
testcase_30 AC 100 ms
77,280 KB
testcase_31 AC 132 ms
78,204 KB
testcase_32 AC 99 ms
77,180 KB
testcase_33 AC 121 ms
78,284 KB
testcase_34 AC 126 ms
77,972 KB
testcase_35 AC 125 ms
78,176 KB
testcase_36 AC 110 ms
77,924 KB
testcase_37 AC 124 ms
78,152 KB
testcase_38 AC 129 ms
78,168 KB
testcase_39 AC 118 ms
78,320 KB
testcase_40 AC 132 ms
78,036 KB
testcase_41 AC 131 ms
78,276 KB
testcase_42 AC 124 ms
78,320 KB
testcase_43 AC 115 ms
78,176 KB
testcase_44 AC 92 ms
71,648 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
    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
            DP[A[i]]=i
        if DP[K]==-1:
            ans+=v

print(ans)
0