結果

問題 No.1861 Required Number
ユーザー HydruHydru
提出日時 2022-03-05 12:52:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 807 ms / 2,500 ms
コード長 879 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 235,908 KB
最終ジャッジ日時 2023-09-26 22:49:08
合計ジャッジ時間 27,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,216 KB
testcase_01 AC 78 ms
76,096 KB
testcase_02 AC 73 ms
71,316 KB
testcase_03 AC 769 ms
235,560 KB
testcase_04 AC 807 ms
235,908 KB
testcase_05 AC 74 ms
71,624 KB
testcase_06 AC 73 ms
71,388 KB
testcase_07 AC 85 ms
76,120 KB
testcase_08 AC 89 ms
76,056 KB
testcase_09 AC 79 ms
75,952 KB
testcase_10 AC 85 ms
76,060 KB
testcase_11 AC 88 ms
76,196 KB
testcase_12 AC 82 ms
76,192 KB
testcase_13 AC 88 ms
76,124 KB
testcase_14 AC 87 ms
76,216 KB
testcase_15 AC 87 ms
76,012 KB
testcase_16 AC 80 ms
75,992 KB
testcase_17 AC 88 ms
76,332 KB
testcase_18 AC 88 ms
76,220 KB
testcase_19 AC 92 ms
76,256 KB
testcase_20 AC 89 ms
76,112 KB
testcase_21 AC 86 ms
76,208 KB
testcase_22 AC 89 ms
76,260 KB
testcase_23 AC 87 ms
76,236 KB
testcase_24 AC 285 ms
127,732 KB
testcase_25 AC 550 ms
213,356 KB
testcase_26 AC 183 ms
100,200 KB
testcase_27 AC 265 ms
122,612 KB
testcase_28 AC 285 ms
125,356 KB
testcase_29 AC 202 ms
101,060 KB
testcase_30 AC 126 ms
81,244 KB
testcase_31 AC 552 ms
213,732 KB
testcase_32 AC 144 ms
88,940 KB
testcase_33 AC 410 ms
167,792 KB
testcase_34 AC 469 ms
189,420 KB
testcase_35 AC 475 ms
189,696 KB
testcase_36 AC 229 ms
111,480 KB
testcase_37 AC 280 ms
122,308 KB
testcase_38 AC 484 ms
190,748 KB
testcase_39 AC 323 ms
140,472 KB
testcase_40 AC 555 ms
212,344 KB
testcase_41 AC 547 ms
207,600 KB
testcase_42 AC 466 ms
182,888 KB
testcase_43 AC 307 ms
133,112 KB
testcase_44 AC 72 ms
71,316 KB
04_evil_1.txt TLE -
04_evil_2.txt TLE -
04_evil_3.txt TLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import exit
n, k = map(int,input().split())
A = list(map(int,input().split()))

lDP=[[False for _ in range(k+1)] for _ in range(n+1)]
rDP=[[False for _ in range(k+1)] for _ in range(n+1)]

lDP[0][0]=True
for i in range(n):
    for j in range(k+1):
        lDP[i+1][j]=lDP[i][j]
    x=A[i]
    for j in range(k+1):
        if x+j>k:
            break
        if lDP[i][j]:
            lDP[i+1][j+x]=True

if not lDP[n][k]:
    print(-1)
    exit()

rDP[n][0]=True
for i in range(n,0,-1):
    for j in range(k+1):
        rDP[i-1][j]=rDP[i][j]
    x=A[i-1]
    for j in range(k+1):
        if x+j>k:
            break
        if rDP[i][j]:
            rDP[i-1][j+x]=True
ans=0

for i in range(n):
    use_flag = True
    for j in range(k+1):
        if lDP[i][j] and rDP[i+1][k-j]:
            use_flag = False
            break
    if use_flag:
        ans+=1

print(ans)
0