結果

問題 No.324 落ちてた閉路グラフ
ユーザー cielciel
提出日時 2015-12-23 10:48:06
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 591 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 11,964 KB
実行使用メモリ 173,072 KB
最終ジャッジ日時 2023-10-18 23:28:20
合計ジャッジ時間 7,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
16,120 KB
testcase_01 AC 87 ms
16,120 KB
testcase_02 AC 88 ms
16,120 KB
testcase_03 AC 85 ms
16,120 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:20: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
$memo={}
$memo2={}
def dfs(prev,cur,remain)
	if remain<0
		return -Float::INFINITY 
	elsif cur==W.size
		return remain>0 ? -Float::INFINITY : 0
	end
	$memo[[prev,cur,remain]]||=[dfs(0,cur+1,remain),dfs(1,cur+1,remain-1)+W[cur-1]*prev].max
end
def dfs2(prev,cur,remain)
	if remain<0
		return -Float::INFINITY
	elsif cur==W.size
		return remain>0 ? -Float::INFINITY : W[cur-1]*prev
	end
	$memo2[[prev,cur,remain]]||=[dfs2(0,cur+1,remain),dfs2(1,cur+1,remain-1)+W[cur-1]*prev].max
end
n,m,*W=$<.read.split.map(&:to_i)
if m<2
	p 0
	exit
else
	p [dfs(0,1,m),dfs2(1,1,m-1)].max
end
0