結果

問題 No.1861 Required Number
ユーザー chineristACchineristAC
提出日時 2022-03-04 22:33:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,160 ms / 2,500 ms
コード長 842 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 85,284 KB
最終ジャッジ日時 2023-09-26 03:45:10
合計ジャッジ時間 20,098 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
74,820 KB
testcase_01 AC 111 ms
74,460 KB
testcase_02 AC 108 ms
74,756 KB
testcase_03 AC 725 ms
83,912 KB
testcase_04 AC 730 ms
83,936 KB
testcase_05 AC 112 ms
74,168 KB
testcase_06 AC 112 ms
74,632 KB
testcase_07 AC 113 ms
79,132 KB
testcase_08 AC 121 ms
78,972 KB
testcase_09 AC 112 ms
74,168 KB
testcase_10 AC 119 ms
79,332 KB
testcase_11 AC 119 ms
79,228 KB
testcase_12 AC 110 ms
74,272 KB
testcase_13 AC 120 ms
79,196 KB
testcase_14 AC 118 ms
79,284 KB
testcase_15 AC 119 ms
79,116 KB
testcase_16 AC 109 ms
74,176 KB
testcase_17 AC 117 ms
79,112 KB
testcase_18 AC 119 ms
79,320 KB
testcase_19 AC 126 ms
80,304 KB
testcase_20 AC 128 ms
80,724 KB
testcase_21 AC 118 ms
79,196 KB
testcase_22 AC 129 ms
80,564 KB
testcase_23 AC 118 ms
79,184 KB
testcase_24 AC 500 ms
82,836 KB
testcase_25 AC 1,119 ms
85,056 KB
testcase_26 AC 266 ms
82,168 KB
testcase_27 AC 420 ms
83,448 KB
testcase_28 AC 502 ms
83,452 KB
testcase_29 AC 313 ms
83,340 KB
testcase_30 AC 136 ms
81,572 KB
testcase_31 AC 1,160 ms
85,284 KB
testcase_32 AC 194 ms
82,960 KB
testcase_33 AC 774 ms
84,296 KB
testcase_34 AC 919 ms
84,508 KB
testcase_35 AC 918 ms
84,908 KB
testcase_36 AC 317 ms
83,440 KB
testcase_37 AC 460 ms
83,812 KB
testcase_38 AC 941 ms
84,580 KB
testcase_39 AC 517 ms
83,600 KB
testcase_40 AC 1,118 ms
84,684 KB
testcase_41 AC 1,059 ms
84,980 KB
testcase_42 AC 850 ms
84,604 KB
testcase_43 AC 472 ms
83,652 KB
testcase_44 AC 110 ms
74,772 KB
04_evil_1.txt RE -
04_evil_2.txt RE -
04_evil_3.txt RE -
04_evil_4.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

N,K = mi()
A = li()

assert N <= 10**4
assert K <= 10**3

dp = [0 for i in range(N+1)]
dp[0] = 1
mask = 2**(K+1)-1
for i in range(N):
    dp[i+1] = (dp[i]|(dp[i]<<A[i]))&mask

dp_back = [0 for i in range(N+1)]
dp_back[N] = 1
for i in range(N)[::-1]:
    dp_back[i] = (dp_back[i+1]|(dp_back[i+1]<<A[i])) & mask

if dp[-1]>>K & 1 == 0:
    exit(print(-1))

need = 0
for i in range(N):
    flag = True
    for k in range(K+1):
        if dp[i]>>k & 1:
            if dp_back[i+1]>>(K-k) & 1:
                flag = False
    if flag:
        need += 1


print(need)
0