結果

問題 No.2389 Cheating Code Golf
ユーザー 👑 MizarMizar
提出日時 2023-07-20 01:38:27
言語 Ruby
(3.3.0)
結果
AC  
実行時間 903 ms / 2,000 ms
コード長 769 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 11,896 KB
実行使用メモリ 17,596 KB
最終ジャッジ日時 2023-10-20 03:26:42
合計ジャッジ時間 11,601 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
16,112 KB
testcase_01 AC 86 ms
16,108 KB
testcase_02 AC 263 ms
17,360 KB
testcase_03 AC 903 ms
17,596 KB
testcase_04 AC 891 ms
17,596 KB
testcase_05 AC 103 ms
16,408 KB
testcase_06 AC 85 ms
17,164 KB
testcase_07 AC 118 ms
16,340 KB
testcase_08 AC 328 ms
17,072 KB
testcase_09 AC 86 ms
16,900 KB
testcase_10 AC 89 ms
17,428 KB
testcase_11 AC 121 ms
16,672 KB
testcase_12 AC 86 ms
16,372 KB
testcase_13 AC 262 ms
17,364 KB
testcase_14 AC 140 ms
16,580 KB
testcase_15 AC 92 ms
16,372 KB
testcase_16 AC 284 ms
16,808 KB
testcase_17 AC 88 ms
16,116 KB
testcase_18 AC 124 ms
16,576 KB
testcase_19 AC 90 ms
16,116 KB
testcase_20 AC 90 ms
16,372 KB
testcase_21 AC 101 ms
16,604 KB
testcase_22 AC 88 ms
16,372 KB
testcase_23 AC 85 ms
16,372 KB
testcase_24 AC 114 ms
16,372 KB
testcase_25 AC 104 ms
16,604 KB
testcase_26 AC 90 ms
16,948 KB
testcase_27 AC 152 ms
16,284 KB
testcase_28 AC 111 ms
16,368 KB
testcase_29 AC 91 ms
17,204 KB
testcase_30 AC 234 ms
17,336 KB
testcase_31 AC 96 ms
16,412 KB
testcase_32 AC 87 ms
16,112 KB
testcase_33 AC 86 ms
16,372 KB
testcase_34 AC 168 ms
16,284 KB
testcase_35 AC 96 ms
16,412 KB
testcase_36 AC 229 ms
17,336 KB
testcase_37 AC 93 ms
17,428 KB
testcase_38 AC 415 ms
17,336 KB
testcase_39 AC 86 ms
17,428 KB
testcase_40 AC 90 ms
17,164 KB
testcase_41 AC 92 ms
16,284 KB
testcase_42 AC 89 ms
16,372 KB
testcase_43 AC 84 ms
16,372 KB
testcase_44 AC 87 ms
17,428 KB
testcase_45 AC 381 ms
16,596 KB
testcase_46 AC 227 ms
16,344 KB
testcase_47 AC 84 ms
16,372 KB
testcase_48 AC 112 ms
16,464 KB
testcase_49 AC 142 ms
16,576 KB
testcase_50 AC 83 ms
16,372 KB
testcase_51 AC 115 ms
16,672 KB
testcase_52 AC 101 ms
16,412 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.split.map(&:to_i)
iabpp = (1..n).map{
	a, b, p = gets.split.map(&:to_f)
	[1.0 / a, 1.0 / b, 1.0 / p, 1.0 - 1.0 / p]
}
dp = Array.new(4096, -Float::INFINITY)
full_bit = (1 << n) - 1

(0..m).each do
	dpc = dp.dup
	dpc[0] = 0.0
	(1..n).each do |i|
		bidx = (1 << i) - 1
		while bidx <= full_bit do
			point = 0.0
			pit = bidx
			while pit > 0 do
				pbit = pit & -pit
				pidx = (pbit - 1).bit_length
				dpidx = bidx ^ pbit
				(af, bf, psucc, pfail) = iabpp[pidx]
				point = [point, dpc[dpidx] + af, (dpc[dpidx] + bf) * psucc + dp[bidx] * pfail].filter(&:finite?).max
				pit &= pit - 1
			end
			dpc[bidx] = [dpc[bidx], point].max
			x = bidx & -bidx
			y = bidx + x
			bidx = ((bidx & ~y) >> x.bit_length) | y
		end
	end
	dp = dpc
end

puts dp[full_bit]
0