結果

問題 No.1861 Required Number
ユーザー roarisroaris
提出日時 2022-03-04 21:58:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 507 ms / 2,500 ms
コード長 700 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 144,312 KB
最終ジャッジ日時 2023-09-26 03:29:31
合計ジャッジ時間 24,799 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
71,692 KB
testcase_01 AC 97 ms
76,776 KB
testcase_02 AC 90 ms
71,848 KB
testcase_03 AC 492 ms
144,120 KB
testcase_04 AC 459 ms
144,296 KB
testcase_05 AC 89 ms
71,884 KB
testcase_06 AC 91 ms
71,668 KB
testcase_07 AC 100 ms
76,756 KB
testcase_08 AC 108 ms
77,616 KB
testcase_09 AC 94 ms
76,784 KB
testcase_10 AC 102 ms
77,284 KB
testcase_11 AC 105 ms
77,384 KB
testcase_12 AC 97 ms
77,184 KB
testcase_13 AC 107 ms
77,552 KB
testcase_14 AC 108 ms
77,300 KB
testcase_15 AC 105 ms
77,348 KB
testcase_16 AC 97 ms
76,720 KB
testcase_17 AC 106 ms
77,372 KB
testcase_18 AC 106 ms
77,468 KB
testcase_19 AC 108 ms
77,764 KB
testcase_20 AC 106 ms
77,584 KB
testcase_21 AC 105 ms
77,336 KB
testcase_22 AC 106 ms
77,672 KB
testcase_23 AC 103 ms
77,312 KB
testcase_24 AC 269 ms
99,012 KB
testcase_25 AC 507 ms
144,312 KB
testcase_26 AC 162 ms
78,108 KB
testcase_27 AC 259 ms
98,184 KB
testcase_28 AC 271 ms
98,544 KB
testcase_29 AC 204 ms
94,436 KB
testcase_30 AC 122 ms
77,952 KB
testcase_31 AC 503 ms
144,200 KB
testcase_32 AC 134 ms
78,032 KB
testcase_33 AC 384 ms
121,404 KB
testcase_34 AC 424 ms
121,212 KB
testcase_35 AC 426 ms
121,260 KB
testcase_36 AC 214 ms
95,272 KB
testcase_37 AC 267 ms
98,040 KB
testcase_38 AC 432 ms
121,060 KB
testcase_39 AC 289 ms
98,032 KB
testcase_40 AC 507 ms
143,876 KB
testcase_41 AC 483 ms
143,596 KB
testcase_42 AC 404 ms
120,896 KB
testcase_43 AC 270 ms
98,064 KB
testcase_44 AC 92 ms
71,708 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)
dp1[0] = True
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

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

ans = 0

for i in range(N):
    for j in range(K+1):
        if dp1[j] and dp2[N-1-i][K-j]:
            break
    else:
        ans += 1
    
    for j in range(K, -1, -1):
        if dp1[j] and j+A[i]<=K:
            dp1[j+A[i]] = True

print(ans)
0