結果

問題 No.1861 Required Number
ユーザー shiomusubi496shiomusubi496
提出日時 2022-03-02 10:25:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 851 bytes
コンパイル時間 494 ms
コンパイル使用メモリ 11,012 KB
実行使用メモリ 15,392 KB
最終ジャッジ日時 2023-09-26 03:08:13
合計ジャッジ時間 4,756 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,300 KB
testcase_01 AC 18 ms
8,204 KB
testcase_02 AC 16 ms
7,820 KB
testcase_03 TLE -
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()))

dpl = [[False] * (K + 1) for _ in range(N + 1)]
dpr = [[False] * (K + 1) for _ in range(N + 1)]
dpl[0][0] = dpr[N][0] = True

for i in range(N):
    for j in range(K + 1):
        dpl[i + 1][j] = dpl[i][j]
    for j in range(0, K - A[i] + 1):
        if dpl[i][j]:
            dpl[i + 1][j + A[i]] = True
for i in range(N - 1, -1, -1):
    for j in range(K + 1):
        dpr[i][j] = dpr[i + 1][j]
    for j in range(0, K - A[i] + 1):
        if dpr[i + 1][j]:
            dpr[i][j + A[i]] = True
if not dpl[N][K]:
    print(-1)
else:
    ans = 0
    for i in range(N):
        not_use = True
        for j in range(K + 1):
            if dpl[i][j] and dpr[i + 1][K - j]:
                not_use = False
                break
        if not_use:
            ans += 1
    print(ans)
0