結果

問題 No.1861 Required Number
ユーザー H3PO4H3PO4
提出日時 2022-03-04 21:45:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 215 ms / 2,500 ms
コード長 542 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 59,004 KB
最終ジャッジ日時 2023-09-26 03:22:10
合計ジャッジ時間 12,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
29,592 KB
testcase_01 AC 140 ms
29,608 KB
testcase_02 AC 137 ms
29,576 KB
testcase_03 AC 215 ms
58,808 KB
testcase_04 AC 206 ms
59,004 KB
testcase_05 AC 137 ms
29,692 KB
testcase_06 AC 140 ms
29,576 KB
testcase_07 AC 135 ms
29,564 KB
testcase_08 AC 137 ms
29,688 KB
testcase_09 AC 137 ms
29,596 KB
testcase_10 AC 133 ms
29,584 KB
testcase_11 AC 136 ms
29,628 KB
testcase_12 AC 134 ms
29,560 KB
testcase_13 AC 135 ms
29,660 KB
testcase_14 AC 141 ms
29,684 KB
testcase_15 AC 139 ms
29,612 KB
testcase_16 AC 136 ms
29,392 KB
testcase_17 AC 136 ms
29,600 KB
testcase_18 AC 136 ms
29,656 KB
testcase_19 AC 135 ms
29,808 KB
testcase_20 AC 135 ms
29,756 KB
testcase_21 AC 137 ms
29,540 KB
testcase_22 AC 138 ms
29,720 KB
testcase_23 AC 137 ms
29,652 KB
testcase_24 AC 168 ms
39,672 KB
testcase_25 AC 203 ms
55,496 KB
testcase_26 AC 167 ms
33,924 KB
testcase_27 AC 186 ms
38,896 KB
testcase_28 AC 178 ms
40,408 KB
testcase_29 AC 187 ms
35,868 KB
testcase_30 AC 185 ms
30,968 KB
testcase_31 AC 202 ms
56,108 KB
testcase_32 AC 187 ms
31,992 KB
testcase_33 AC 198 ms
47,624 KB
testcase_34 AC 197 ms
50,848 KB
testcase_35 AC 200 ms
51,468 KB
testcase_36 AC 191 ms
36,016 KB
testcase_37 AC 192 ms
40,036 KB
testcase_38 AC 200 ms
51,664 KB
testcase_39 AC 193 ms
41,760 KB
testcase_40 AC 210 ms
56,032 KB
testcase_41 AC 209 ms
54,492 KB
testcase_42 AC 202 ms
50,000 KB
testcase_43 AC 192 ms
40,108 KB
testcase_44 AC 133 ms
29,500 KB
04_evil_1.txt RE -
04_evil_2.txt RE -
04_evil_3.txt RE -
04_evil_4.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N, K = map(int, input().split())
A = tuple(map(int, input().split()))

dp1 = np.zeros((N + 1, K + 1), dtype=bool)
dp2 = np.zeros((N + 1, K + 1), dtype=bool)

dp1[:, 0] = True
dp2[:, 0] = True

for i in range(N):
    a = A[i]
    dp1[i + 1] = dp1[i]
    dp1[i + 1, a:] |= dp1[i, :K + 1 - a]
for i in range(N - 1, -1, -1):
    a = A[i]
    dp2[i] = dp2[i + 1]
    dp2[i, a:] |= dp2[i + 1, :K + 1 - a]

if not dp1[-1, K]:
    print(-1)
    exit()

ans = np.count_nonzero(~np.any(dp1[:-1] & dp2[1:, ::-1], axis=1))
print(ans)
0