結果

問題 No.1861 Required Number
ユーザー roarisroaris
提出日時 2022-03-04 21:48:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 824 ms / 2,500 ms
コード長 836 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 232,672 KB
最終ジャッジ日時 2023-09-26 03:25:55
合計ジャッジ時間 29,422 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
71,536 KB
testcase_01 AC 97 ms
76,808 KB
testcase_02 AC 91 ms
71,480 KB
testcase_03 AC 740 ms
232,300 KB
testcase_04 AC 737 ms
232,672 KB
testcase_05 AC 90 ms
71,688 KB
testcase_06 AC 90 ms
71,636 KB
testcase_07 AC 99 ms
76,812 KB
testcase_08 AC 108 ms
77,172 KB
testcase_09 AC 96 ms
76,748 KB
testcase_10 AC 106 ms
77,028 KB
testcase_11 AC 105 ms
77,272 KB
testcase_12 AC 98 ms
76,888 KB
testcase_13 AC 107 ms
77,308 KB
testcase_14 AC 103 ms
77,112 KB
testcase_15 AC 108 ms
77,020 KB
testcase_16 AC 96 ms
76,756 KB
testcase_17 AC 102 ms
77,352 KB
testcase_18 AC 105 ms
77,132 KB
testcase_19 AC 108 ms
77,872 KB
testcase_20 AC 108 ms
77,556 KB
testcase_21 AC 108 ms
77,248 KB
testcase_22 AC 109 ms
77,528 KB
testcase_23 AC 106 ms
76,920 KB
testcase_24 AC 378 ms
118,276 KB
testcase_25 AC 816 ms
209,400 KB
testcase_26 AC 230 ms
94,884 KB
testcase_27 AC 363 ms
117,348 KB
testcase_28 AC 417 ms
134,148 KB
testcase_29 AC 283 ms
110,164 KB
testcase_30 AC 138 ms
78,112 KB
testcase_31 AC 816 ms
209,364 KB
testcase_32 AC 179 ms
89,808 KB
testcase_33 AC 596 ms
162,624 KB
testcase_34 AC 690 ms
185,856 KB
testcase_35 AC 698 ms
186,032 KB
testcase_36 AC 274 ms
112,168 KB
testcase_37 AC 387 ms
116,932 KB
testcase_38 AC 697 ms
186,216 KB
testcase_39 AC 452 ms
140,148 KB
testcase_40 AC 824 ms
209,052 KB
testcase_41 AC 790 ms
208,636 KB
testcase_42 AC 661 ms
183,884 KB
testcase_43 AC 412 ms
133,556 KB
testcase_44 AC 89 ms
71,652 KB
04_evil_1.txt TLE -
04_evil_2.txt TLE -
04_evil_3.txt TLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
dp1 = [[False]*(K+1) for _ in range(N+1)]
dp1[0][0] = True

for i in range(N):
    for j in range(K+1):
        if dp1[i][j]:
            dp1[i+1][j] = True
            
            if j+A[i]<=K:
                dp1[i+1][j+A[i]] = True

if not dp1[N][K]:
    exit(print(-1))

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

for i in range(N):
    for j in range(K+1):
        if dp2[i][j]:
            dp2[i+1][j] = True
            
            if j+A[N-1-i]<=K:
                dp2[i+1][j+A[N-1-i]] = True

ans = 0

for i in range(N):
    ok = True
    
    for j in range(K+1):
        if dp1[i][j] and dp2[N-1-i][K-j]:
            ok = False
    
    if ok:
        ans += 1

print(ans)
0