結果

問題 No.1861 Required Number
ユーザー AEnAEn
提出日時 2022-11-22 23:42:47
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 714 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 81,760 KB
実行使用メモリ 839,804 KB
最終ジャッジ日時 2023-10-24 14:30:29
合計ジャッジ時間 7,100 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,432 KB
testcase_01 AC 43 ms
59,480 KB
testcase_02 AC 37 ms
53,432 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
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 #

N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = [[0]*(K+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1,N+1):
    a = A[i-1]
    for j in range(K+1):
        dp[i][j] += dp[i-1][j]
        if j+a<=K:
            dp[i][j+a] += dp[i-1][j]

if dp[-1][-1]==0:
    exit(print(-1))

dpr = [set() for _ in range(N+1)]
dpr[-1].add(K)
ans = 0
for i in range(N,0,-1):
    a = A[i-1]
    c1, c2 = 0, 0
    for num in dpr[i]:
        if dp[i-1][num]>0:
            c1 += 1
            dpr[i-1].add(num)
        if num-a>=0 and dp[i-1][num-a]>0:
            c2 += 1
            dpr[i-1].add(num-a)
    l = len(dpr[i])
    if (c1==l and c2==0) or (c1==0 and c2==l):
        ans += 1
print(ans)

0