結果

問題 No.1861 Required Number
ユーザー ygd.ygd.
提出日時 2022-03-05 11:25:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 596 ms / 2,500 ms
コード長 1,519 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 235,328 KB
最終ジャッジ日時 2023-09-26 17:47:45
合計ジャッジ時間 17,983 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,260 KB
testcase_01 AC 77 ms
75,704 KB
testcase_02 AC 73 ms
71,228 KB
testcase_03 AC 543 ms
226,200 KB
testcase_04 AC 596 ms
235,328 KB
testcase_05 AC 74 ms
70,944 KB
testcase_06 AC 73 ms
71,024 KB
testcase_07 AC 83 ms
75,792 KB
testcase_08 AC 87 ms
75,584 KB
testcase_09 AC 82 ms
75,320 KB
testcase_10 AC 84 ms
75,636 KB
testcase_11 AC 86 ms
75,692 KB
testcase_12 AC 83 ms
75,684 KB
testcase_13 AC 86 ms
75,412 KB
testcase_14 AC 88 ms
75,560 KB
testcase_15 AC 84 ms
75,640 KB
testcase_16 AC 83 ms
75,640 KB
testcase_17 AC 86 ms
75,720 KB
testcase_18 AC 87 ms
75,748 KB
testcase_19 AC 89 ms
75,396 KB
testcase_20 AC 86 ms
75,548 KB
testcase_21 AC 82 ms
75,824 KB
testcase_22 AC 87 ms
75,548 KB
testcase_23 AC 86 ms
75,420 KB
testcase_24 AC 244 ms
130,308 KB
testcase_25 AC 460 ms
203,220 KB
testcase_26 AC 151 ms
89,208 KB
testcase_27 AC 217 ms
111,024 KB
testcase_28 AC 251 ms
133,252 KB
testcase_29 AC 182 ms
109,348 KB
testcase_30 AC 116 ms
84,356 KB
testcase_31 AC 438 ms
202,836 KB
testcase_32 AC 128 ms
88,268 KB
testcase_33 AC 327 ms
157,100 KB
testcase_34 AC 385 ms
180,220 KB
testcase_35 AC 380 ms
179,924 KB
testcase_36 AC 188 ms
110,608 KB
testcase_37 AC 246 ms
130,764 KB
testcase_38 AC 396 ms
180,320 KB
testcase_39 AC 267 ms
134,160 KB
testcase_40 AC 458 ms
202,948 KB
testcase_41 AC 425 ms
203,296 KB
testcase_42 AC 362 ms
179,876 KB
testcase_43 AC 239 ms
132,344 KB
testcase_44 AC 74 ms
71,156 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):
        for j in range(K+1):
            #使わない
            dpl[i+1][j] |= dpl[i][j]
            #使う
            if j+A[i] <= K:
                dpl[i+1][j+A[i]] |= dpl[i][j]
        for j in range(K+1):
            #使わない
            dpr[i+1][j] |= dpr[i][j]
            #使う
            if j+A[N-1-i] <= K:
                dpr[i+1][j+A[N-1-i]] |= 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