結果

問題 No.1861 Required Number
ユーザー ygd.ygd.
提出日時 2022-03-05 11:32:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 604 ms / 2,500 ms
コード長 1,617 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 235,328 KB
最終ジャッジ日時 2023-09-26 18:10:12
合計ジャッジ時間 19,423 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,160 KB
testcase_01 AC 73 ms
75,256 KB
testcase_02 AC 71 ms
71,160 KB
testcase_03 AC 547 ms
226,132 KB
testcase_04 AC 604 ms
235,328 KB
testcase_05 AC 72 ms
71,544 KB
testcase_06 AC 70 ms
71,272 KB
testcase_07 AC 75 ms
75,172 KB
testcase_08 AC 81 ms
75,924 KB
testcase_09 AC 73 ms
75,040 KB
testcase_10 AC 81 ms
75,732 KB
testcase_11 AC 81 ms
75,932 KB
testcase_12 AC 78 ms
75,840 KB
testcase_13 AC 83 ms
75,724 KB
testcase_14 AC 83 ms
76,020 KB
testcase_15 AC 83 ms
75,928 KB
testcase_16 AC 76 ms
75,204 KB
testcase_17 AC 83 ms
75,760 KB
testcase_18 AC 82 ms
75,904 KB
testcase_19 AC 84 ms
75,936 KB
testcase_20 AC 83 ms
75,732 KB
testcase_21 AC 81 ms
75,724 KB
testcase_22 AC 82 ms
75,948 KB
testcase_23 AC 83 ms
75,904 KB
testcase_24 AC 272 ms
130,536 KB
testcase_25 AC 532 ms
203,512 KB
testcase_26 AC 163 ms
89,760 KB
testcase_27 AC 252 ms
111,572 KB
testcase_28 AC 286 ms
133,592 KB
testcase_29 AC 209 ms
109,184 KB
testcase_30 AC 119 ms
84,640 KB
testcase_31 AC 540 ms
203,128 KB
testcase_32 AC 130 ms
88,244 KB
testcase_33 AC 408 ms
171,336 KB
testcase_34 AC 461 ms
180,448 KB
testcase_35 AC 461 ms
180,308 KB
testcase_36 AC 202 ms
111,184 KB
testcase_37 AC 281 ms
131,132 KB
testcase_38 AC 465 ms
180,552 KB
testcase_39 AC 306 ms
134,396 KB
testcase_40 AC 535 ms
203,004 KB
testcase_41 AC 517 ms
203,496 KB
testcase_42 AC 441 ms
180,328 KB
testcase_43 AC 286 ms
132,632 KB
testcase_44 AC 71 ms
71,404 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]

def main():
    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)

if __name__ == '__main__':
    main()
0