結果

問題 No.1861 Required Number
ユーザー NatsubiSoganNatsubiSogan
提出日時 2022-03-04 22:09:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 710 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 157,296 KB
最終ジャッジ日時 2023-09-26 03:35:49
合計ジャッジ時間 20,168 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,352 KB
testcase_01 AC 78 ms
76,124 KB
testcase_02 AC 73 ms
71,200 KB
testcase_03 AC 351 ms
156,792 KB
testcase_04 WA -
testcase_05 AC 73 ms
71,356 KB
testcase_06 AC 72 ms
71,404 KB
testcase_07 AC 80 ms
76,012 KB
testcase_08 AC 85 ms
76,112 KB
testcase_09 AC 83 ms
76,004 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 84 ms
75,988 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 85 ms
76,012 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 AC 72 ms
71,396 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0] * (k + 1) for _ in range(n + 1)]
dp[0][0] = 1
mem = [-1] * (k + 1)
for i in range(n):
	for j in range(k + 1):
		if j - a[i] >= 0: dp[i + 1][j] |= dp[i][j - a[i]]
		dp[i + 1][j] |= dp[i][j]
		if mem[j] == -1 and dp[i + 1][j]:
			mem[j] = i + 1
if not dp[n][k]: exit(print(-1))
now = (n, k)
l1 = []
while now != (0, 0):
	cn, ck = now
	if dp[cn - 1][ck - a[cn - 1]]:
		l1.append(cn - 1)
		now = (cn - 1, ck - a[cn - 1])
	else:
		now = (cn - 1, ck)
l2 = []
now = (n, k)
while now != (0, 0):
	cn, ck = now
	if dp[cn - 1][ck]:
		now = (cn - 1, ck)
	else:
		l2.append(cn - 1)
		now = (cn - 1, ck - a[cn - 1])
print(len(set(l1) & set(l2)))
0