結果

問題 No.1861 Required Number
ユーザー 👑 H20H20
提出日時 2022-03-04 23:14:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,001 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 176,496 KB
最終ジャッジ日時 2023-09-26 03:55:34
合計ジャッジ時間 25,433 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
164,368 KB
testcase_01 AC 98 ms
81,356 KB
testcase_02 AC 93 ms
164,584 KB
testcase_03 WA -
testcase_04 AC 101 ms
176,496 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 100 ms
77,280 KB
testcase_08 AC 112 ms
77,204 KB
testcase_09 AC 97 ms
76,828 KB
testcase_10 AC 122 ms
77,532 KB
testcase_11 AC 113 ms
77,136 KB
testcase_12 AC 98 ms
76,840 KB
testcase_13 AC 120 ms
77,344 KB
testcase_14 AC 110 ms
77,092 KB
testcase_15 AC 112 ms
77,636 KB
testcase_16 AC 99 ms
76,996 KB
testcase_17 AC 108 ms
77,292 KB
testcase_18 AC 117 ms
77,292 KB
testcase_19 AC 121 ms
77,648 KB
testcase_20 AC 127 ms
77,356 KB
testcase_21 AC 118 ms
77,800 KB
testcase_22 AC 123 ms
77,676 KB
testcase_23 AC 111 ms
77,248 KB
testcase_24 AC 287 ms
78,072 KB
testcase_25 AC 470 ms
78,456 KB
testcase_26 AC 142 ms
78,540 KB
testcase_27 AC 160 ms
78,416 KB
testcase_28 AC 224 ms
78,288 KB
testcase_29 AC 138 ms
78,268 KB
testcase_30 AC 100 ms
77,260 KB
testcase_31 AC 539 ms
78,860 KB
testcase_32 AC 99 ms
77,220 KB
testcase_33 AC 318 ms
78,692 KB
testcase_34 AC 395 ms
78,584 KB
testcase_35 AC 373 ms
79,112 KB
testcase_36 AC 140 ms
78,460 KB
testcase_37 AC 168 ms
78,324 KB
testcase_38 AC 408 ms
78,372 KB
testcase_39 AC 196 ms
78,816 KB
testcase_40 AC 439 ms
78,524 KB
testcase_41 AC 487 ms
78,600 KB
testcase_42 AC 307 ms
78,476 KB
testcase_43 AC 187 ms
78,612 KB
testcase_44 AC 91 ms
71,716 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()))

CA = collections.Counter(A)
if sum(A)==K:
    print(N)
    exit()
if CA[1]>K:
    print(0)
    exit()


A.sort()
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)

A.sort(reverse=True)
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)
CC = collections.Counter(B)

CC = CC-CB

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


for k,v in CC.items():
    if CC[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