結果

問題 No.1861 Required Number
ユーザー shobonvipshobonvip
提出日時 2022-03-04 22:19:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 583 ms / 2,500 ms
コード長 720 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 232,596 KB
最終ジャッジ日時 2023-09-26 03:38:29
合計ジャッジ時間 18,099 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,340 KB
testcase_01 AC 77 ms
76,200 KB
testcase_02 AC 71 ms
71,532 KB
testcase_03 AC 459 ms
232,552 KB
testcase_04 AC 452 ms
232,596 KB
testcase_05 AC 71 ms
71,088 KB
testcase_06 AC 71 ms
71,428 KB
testcase_07 AC 81 ms
76,220 KB
testcase_08 AC 85 ms
76,092 KB
testcase_09 AC 76 ms
76,220 KB
testcase_10 AC 85 ms
76,428 KB
testcase_11 AC 80 ms
76,196 KB
testcase_12 AC 77 ms
76,144 KB
testcase_13 AC 87 ms
76,300 KB
testcase_14 AC 82 ms
76,064 KB
testcase_15 AC 89 ms
76,300 KB
testcase_16 AC 77 ms
76,204 KB
testcase_17 AC 80 ms
76,088 KB
testcase_18 AC 85 ms
76,348 KB
testcase_19 AC 90 ms
76,280 KB
testcase_20 AC 88 ms
76,148 KB
testcase_21 AC 89 ms
76,300 KB
testcase_22 AC 90 ms
76,420 KB
testcase_23 AC 82 ms
76,268 KB
testcase_24 AC 284 ms
125,236 KB
testcase_25 AC 564 ms
210,584 KB
testcase_26 AC 191 ms
100,528 KB
testcase_27 AC 275 ms
120,184 KB
testcase_28 AC 291 ms
123,044 KB
testcase_29 AC 215 ms
98,856 KB
testcase_30 AC 119 ms
81,200 KB
testcase_31 AC 583 ms
210,768 KB
testcase_32 AC 138 ms
83,896 KB
testcase_33 AC 440 ms
164,824 KB
testcase_34 AC 505 ms
187,688 KB
testcase_35 AC 503 ms
186,780 KB
testcase_36 AC 222 ms
99,184 KB
testcase_37 AC 292 ms
119,892 KB
testcase_38 AC 515 ms
188,020 KB
testcase_39 AC 331 ms
140,748 KB
testcase_40 AC 581 ms
209,768 KB
testcase_41 AC 559 ms
207,800 KB
testcase_42 AC 485 ms
183,428 KB
testcase_43 AC 301 ms
120,268 KB
testcase_44 AC 71 ms
71,356 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())
dp = [[0 for i in range(k + 1)] for j in range(n + 1)]
dp[0][0] = 1
a = list(map(int,input().split()))

for i in range(n):
	for j in range(k+1):
		dp[i+1][j] |= dp[i][j]
		if j + a[i] <= k:
			dp[i+1][j + a[i]] |= dp[i][j]

if dp[n][k] == 0:
	print(-1)
	exit()

fukugendp = [[0 for i in range(k + 1)] for j in range(n+1)]
fukugendp[n][k] = 1

t = 0

for i in range(n-1, -1, -1):
	mode = 1
	for j in range(k, -1, -1):
		if fukugendp[i+1][j] == 1:
			if dp[i][j] == 1:
				fukugendp[i][j] = 1
			if j-a[i] >= 0:
				if dp[i][j - a[i]] == 1:
					fukugendp[i][j - a[i]] = 1
			if fukugendp[i][j] == 1:
				mode = 0
	if mode:
		t += 1
			
#for i in range(n+1):
#	print(fukugendp[i])

print(t)
0