結果

問題 No.1861 Required Number
ユーザー ygd.ygd.
提出日時 2022-03-05 11:34:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 590 ms / 2,500 ms
コード長 1,414 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 226,356 KB
最終ジャッジ日時 2023-09-26 18:12:47
合計ジャッジ時間 19,398 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,368 KB
testcase_01 AC 77 ms
75,564 KB
testcase_02 AC 73 ms
71,356 KB
testcase_03 AC 536 ms
226,260 KB
testcase_04 AC 590 ms
226,356 KB
testcase_05 AC 73 ms
71,124 KB
testcase_06 AC 73 ms
70,992 KB
testcase_07 AC 80 ms
76,000 KB
testcase_08 AC 90 ms
76,160 KB
testcase_09 AC 78 ms
75,656 KB
testcase_10 AC 85 ms
76,188 KB
testcase_11 AC 85 ms
76,204 KB
testcase_12 AC 82 ms
76,040 KB
testcase_13 AC 85 ms
75,888 KB
testcase_14 AC 87 ms
76,160 KB
testcase_15 AC 86 ms
76,052 KB
testcase_16 AC 78 ms
75,648 KB
testcase_17 AC 85 ms
76,120 KB
testcase_18 AC 84 ms
75,916 KB
testcase_19 AC 88 ms
75,904 KB
testcase_20 AC 85 ms
76,064 KB
testcase_21 AC 83 ms
76,140 KB
testcase_22 AC 85 ms
76,020 KB
testcase_23 AC 89 ms
76,132 KB
testcase_24 AC 271 ms
130,760 KB
testcase_25 AC 525 ms
203,416 KB
testcase_26 AC 161 ms
89,584 KB
testcase_27 AC 243 ms
111,776 KB
testcase_28 AC 283 ms
133,604 KB
testcase_29 AC 211 ms
109,356 KB
testcase_30 AC 119 ms
84,676 KB
testcase_31 AC 514 ms
203,592 KB
testcase_32 AC 133 ms
88,156 KB
testcase_33 AC 397 ms
171,296 KB
testcase_34 AC 447 ms
180,524 KB
testcase_35 AC 451 ms
180,580 KB
testcase_36 AC 200 ms
111,432 KB
testcase_37 AC 277 ms
130,992 KB
testcase_38 AC 451 ms
180,596 KB
testcase_39 AC 296 ms
134,688 KB
testcase_40 AC 528 ms
203,268 KB
testcase_41 AC 506 ms
203,556 KB
testcase_42 AC 432 ms
180,316 KB
testcase_43 AC 277 ms
132,816 KB
testcase_44 AC 72 ms
71,280 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]


N,K = map(int,input().split())
A = list(map(int,input().split()))
#dpl[i][j]:左からi番目まで見て和がjを作れるか0/1
dpl = [[0]*(K+1) for _ in range(N+1)]
dpl[0][0] = 1
#dpr[i][j]:右からi番目まで見て和がjを作れるか0/1
dpr = [[0]*(K+1) for _ in range(N+1)]
dpr[0][0] = 1
#配るDP
for i in range(N):
    a = A[i]
    for j in range(K+1):
        if dpl[i][j] == 0: continue
        #使わない
        dpl[i+1][j] |= dpl[i][j]
        #使う
        if j+a <= K:
            dpl[i+1][j+a] |= dpl[i][j]
    a = A[N-1-i]
    for j in range(K+1):
        if dpr[i][j] == 0: continue
        #使わない
        dpr[i+1][j] |= dpr[i][j]
        #使う
        if j+a <= K:
            dpr[i+1][j+a] |= dpr[i][j]
if dpl[N][K] == 0:
    print(-1);exit()
#print(dpl)
#print(dpr)
ans = 0
for i in range(N):
    for x in range(K+1):
        if dpl[i][x] == 1 and dpr[N-1-i][K-x] == 1:
            break
    else:
        ans += 1
print(ans)
0