結果

問題 No.1701 half price
ユーザー 小野寺健小野寺健
提出日時 2021-10-30 21:23:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 2,231 ms / 3,000 ms
コード長 355 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 332,800 KB
最終ジャッジ日時 2024-04-16 16:28:21
合計ジャッジ時間 6,171 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
12,160 KB
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 91 ms
12,032 KB
testcase_03 AC 90 ms
12,288 KB
testcase_04 AC 93 ms
12,032 KB
testcase_05 AC 88 ms
12,288 KB
testcase_06 AC 90 ms
12,288 KB
testcase_07 AC 104 ms
12,928 KB
testcase_08 AC 86 ms
12,160 KB
testcase_09 AC 88 ms
12,160 KB
testcase_10 AC 89 ms
12,288 KB
testcase_11 AC 87 ms
12,160 KB
testcase_12 AC 88 ms
12,160 KB
testcase_13 AC 91 ms
12,160 KB
testcase_14 AC 89 ms
12,160 KB
testcase_15 AC 87 ms
12,288 KB
testcase_16 AC 89 ms
12,160 KB
testcase_17 AC 1,235 ms
129,536 KB
testcase_18 AC 95 ms
12,288 KB
testcase_19 AC 103 ms
12,544 KB
testcase_20 AC 88 ms
12,160 KB
testcase_21 AC 2,231 ms
332,800 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, W = gets.split(" ").map{|s| s.to_i}

a = gets.split(" ").map{|s| s.to_i}

w0 = [[0, []]]

0.upto(N-1) {|i|
	w1 = []
	w0.each {|w, v|
		w1 << [w, v]
		tmp = [w + a[i] / 2, v + [i]]
		w1 << tmp if tmp[0] <= W
		tmp = [w + a[i], v + [i]]
		w1 << tmp if tmp[0] <= W
	}
	w0 = w1
}

w0.shift if W == 0

puts w0.filter{|x, y| x == W}.map{|x, y| y}.uniq.length
0