結果

問題 No.1861 Required Number
ユーザー NatsubiSoganNatsubiSogan
提出日時 2022-03-04 22:13:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 823 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 156,756 KB
最終ジャッジ日時 2023-09-26 03:36:40
合計ジャッジ時間 13,798 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,168 KB
testcase_01 AC 77 ms
75,648 KB
testcase_02 AC 74 ms
70,932 KB
testcase_03 AC 268 ms
156,556 KB
testcase_04 WA -
testcase_05 AC 78 ms
70,956 KB
testcase_06 AC 77 ms
71,516 KB
testcase_07 AC 83 ms
75,672 KB
testcase_08 AC 83 ms
75,700 KB
testcase_09 AC 80 ms
75,580 KB
testcase_10 AC 78 ms
75,408 KB
testcase_11 AC 80 ms
75,544 KB
testcase_12 AC 81 ms
75,524 KB
testcase_13 WA -
testcase_14 AC 84 ms
75,516 KB
testcase_15 AC 81 ms
75,656 KB
testcase_16 AC 81 ms
75,316 KB
testcase_17 AC 80 ms
75,528 KB
testcase_18 AC 81 ms
75,548 KB
testcase_19 AC 82 ms
75,748 KB
testcase_20 WA -
testcase_21 AC 79 ms
75,560 KB
testcase_22 AC 82 ms
75,548 KB
testcase_23 AC 82 ms
75,588 KB
testcase_24 AC 142 ms
90,088 KB
testcase_25 AC 247 ms
134,640 KB
testcase_26 AC 116 ms
88,540 KB
testcase_27 AC 138 ms
89,164 KB
testcase_28 AC 141 ms
89,444 KB
testcase_29 AC 130 ms
88,596 KB
testcase_30 AC 98 ms
76,484 KB
testcase_31 AC 240 ms
134,744 KB
testcase_32 AC 96 ms
76,332 KB
testcase_33 AC 189 ms
111,528 KB
testcase_34 AC 229 ms
132,960 KB
testcase_35 AC 227 ms
133,964 KB
testcase_36 AC 129 ms
88,980 KB
testcase_37 AC 142 ms
88,432 KB
testcase_38 AC 223 ms
134,572 KB
testcase_39 AC 164 ms
108,608 KB
testcase_40 AC 244 ms
134,456 KB
testcase_41 AC 236 ms
134,812 KB
testcase_42 AC 214 ms
129,932 KB
testcase_43 AC 146 ms
88,836 KB
testcase_44 AC 73 ms
71,484 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 0 <= cn - 1 <= n and 0 <= ck - a[cn - 1] <= k and 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 0 <= cn - 1 <= n and 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