結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,276 KB
testcase_01 AC 85 ms
75,524 KB
testcase_02 AC 77 ms
71,284 KB
testcase_03 AC 516 ms
225,876 KB
testcase_04 AC 561 ms
235,404 KB
testcase_05 AC 75 ms
71,080 KB
testcase_06 AC 82 ms
71,276 KB
testcase_07 AC 88 ms
75,740 KB
testcase_08 AC 92 ms
75,732 KB
testcase_09 AC 86 ms
75,656 KB
testcase_10 AC 91 ms
75,460 KB
testcase_11 AC 93 ms
75,720 KB
testcase_12 AC 89 ms
75,616 KB
testcase_13 AC 90 ms
75,448 KB
testcase_14 AC 92 ms
75,724 KB
testcase_15 AC 90 ms
75,540 KB
testcase_16 AC 89 ms
75,556 KB
testcase_17 AC 94 ms
75,556 KB
testcase_18 AC 92 ms
75,612 KB
testcase_19 AC 92 ms
75,728 KB
testcase_20 AC 94 ms
75,724 KB
testcase_21 AC 89 ms
75,616 KB
testcase_22 AC 91 ms
75,616 KB
testcase_23 AC 96 ms
75,632 KB
testcase_24 AC 240 ms
130,268 KB
testcase_25 AC 435 ms
203,244 KB
testcase_26 AC 144 ms
89,256 KB
testcase_27 AC 199 ms
111,200 KB
testcase_28 AC 240 ms
133,212 KB
testcase_29 AC 187 ms
108,992 KB
testcase_30 AC 115 ms
84,196 KB
testcase_31 AC 401 ms
203,220 KB
testcase_32 AC 125 ms
88,008 KB
testcase_33 AC 298 ms
157,088 KB
testcase_34 AC 339 ms
180,188 KB
testcase_35 AC 346 ms
179,800 KB
testcase_36 AC 180 ms
110,684 KB
testcase_37 AC 227 ms
130,836 KB
testcase_38 AC 367 ms
180,416 KB
testcase_39 AC 245 ms
134,008 KB
testcase_40 AC 416 ms
202,584 KB
testcase_41 AC 391 ms
203,068 KB
testcase_42 AC 341 ms
179,756 KB
testcase_43 AC 231 ms
132,536 KB
testcase_44 AC 74 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]

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