結果

問題 No.1861 Required Number
ユーザー ygd.ygd.
提出日時 2022-03-05 11:20:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 572 ms / 2,500 ms
コード長 1,537 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 235,176 KB
最終ジャッジ日時 2023-09-26 17:36:49
合計ジャッジ時間 16,552 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,264 KB
testcase_01 AC 99 ms
75,700 KB
testcase_02 AC 80 ms
71,008 KB
testcase_03 AC 519 ms
226,076 KB
testcase_04 AC 572 ms
235,176 KB
testcase_05 AC 74 ms
71,332 KB
testcase_06 AC 76 ms
71,404 KB
testcase_07 AC 87 ms
75,684 KB
testcase_08 AC 89 ms
75,532 KB
testcase_09 AC 84 ms
75,608 KB
testcase_10 AC 86 ms
75,432 KB
testcase_11 AC 88 ms
75,692 KB
testcase_12 AC 82 ms
75,628 KB
testcase_13 AC 88 ms
75,804 KB
testcase_14 AC 87 ms
75,728 KB
testcase_15 AC 85 ms
75,772 KB
testcase_16 AC 82 ms
75,824 KB
testcase_17 AC 85 ms
75,936 KB
testcase_18 AC 85 ms
75,968 KB
testcase_19 AC 87 ms
75,700 KB
testcase_20 AC 86 ms
75,780 KB
testcase_21 AC 82 ms
75,632 KB
testcase_22 AC 86 ms
75,820 KB
testcase_23 AC 83 ms
75,776 KB
testcase_24 AC 225 ms
130,272 KB
testcase_25 AC 413 ms
203,380 KB
testcase_26 AC 144 ms
89,408 KB
testcase_27 AC 200 ms
111,504 KB
testcase_28 AC 234 ms
133,268 KB
testcase_29 AC 177 ms
109,028 KB
testcase_30 AC 119 ms
84,312 KB
testcase_31 AC 417 ms
203,200 KB
testcase_32 AC 124 ms
88,180 KB
testcase_33 AC 310 ms
156,984 KB
testcase_34 AC 358 ms
180,300 KB
testcase_35 AC 356 ms
180,080 KB
testcase_36 AC 189 ms
110,712 KB
testcase_37 AC 236 ms
130,996 KB
testcase_38 AC 365 ms
180,380 KB
testcase_39 AC 252 ms
134,240 KB
testcase_40 AC 420 ms
203,016 KB
testcase_41 AC 404 ms
203,284 KB
testcase_42 AC 348 ms
179,952 KB
testcase_43 AC 234 ms
132,588 KB
testcase_44 AC 76 ms
71,028 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):
            #使わない
            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):
            #使わない
            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