結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,368 KB
testcase_01 AC 76 ms
75,704 KB
testcase_02 AC 73 ms
71,416 KB
testcase_03 AC 260 ms
156,884 KB
testcase_04 WA -
testcase_05 AC 72 ms
71,424 KB
testcase_06 AC 72 ms
71,168 KB
testcase_07 AC 78 ms
75,776 KB
testcase_08 AC 80 ms
75,928 KB
testcase_09 AC 78 ms
75,880 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 77 ms
75,700 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 79 ms
75,668 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 71 ms
71,216 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
	import sys
	input = sys.stdin.readline
	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
	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 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)))
if __name__ == '__main__':
	main()
	
0