結果

問題 No.324 落ちてた閉路グラフ
ユーザー cielciel
提出日時 2017-01-19 15:39:33
言語 Crystal
(1.11.2)
結果
AC  
実行時間 306 ms / 5,000 ms
コード長 528 bytes
コンパイル時間 20,835 ms
コンパイル使用メモリ 254,408 KB
実行使用メモリ 161,636 KB
最終ジャッジ日時 2023-09-13 09:25:55
合計ジャッジ時間 23,084 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
161,024 KB
testcase_01 AC 63 ms
160,956 KB
testcase_02 AC 59 ms
160,992 KB
testcase_03 AC 58 ms
160,992 KB
testcase_04 AC 306 ms
161,328 KB
testcase_05 AC 79 ms
161,384 KB
testcase_06 AC 280 ms
161,360 KB
testcase_07 AC 162 ms
161,276 KB
testcase_08 AC 290 ms
161,340 KB
testcase_09 AC 180 ms
161,384 KB
testcase_10 AC 286 ms
161,444 KB
testcase_11 AC 177 ms
161,452 KB
testcase_12 AC 58 ms
161,092 KB
testcase_13 AC 58 ms
161,268 KB
testcase_14 AC 60 ms
160,996 KB
testcase_15 AC 58 ms
161,072 KB
testcase_16 AC 59 ms
160,876 KB
testcase_17 AC 58 ms
160,960 KB
testcase_18 AC 57 ms
161,040 KB
testcase_19 AC 56 ms
161,000 KB
testcase_20 AC 57 ms
160,944 KB
testcase_21 AC 57 ms
161,000 KB
testcase_22 AC 59 ms
161,136 KB
testcase_23 AC 59 ms
161,068 KB
testcase_24 AC 57 ms
161,036 KB
testcase_25 AC 57 ms
160,956 KB
testcase_26 AC 58 ms
161,104 KB
testcase_27 AC 59 ms
160,956 KB
testcase_28 AC 58 ms
160,960 KB
testcase_29 AC 58 ms
160,876 KB
testcase_30 AC 58 ms
161,020 KB
testcase_31 AC 57 ms
160,904 KB
testcase_32 AC 112 ms
161,636 KB
testcase_33 AC 237 ms
161,452 KB
testcase_34 AC 236 ms
161,316 KB
testcase_35 AC 60 ms
161,012 KB
testcase_36 AC 123 ms
161,148 KB
testcase_37 AC 57 ms
161,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env crystal
MIN=-100000000
Memo=Array(Int32).new(40000000,MIN)
def dfs(n,w,z,prev,cur,remain)
	key=z*20000000+prev*10000000+cur*3100+remain
	if remain<0 || remain>n-cur
		MIN
	elsif cur==n
		w[cur-1]*prev*z
	elsif Memo[key]!=MIN
		Memo[key]
	else
		r1=dfs(n,w,z,0,cur+1,remain)
		r2=dfs(n,w,z,1,cur+1,remain-1)+w[cur-1]*prev
		Memo[key] = r1>r2 ? r1 : r2
	end
end
n,m=gets.not_nil!.split.map(&.to_i)
w=gets.not_nil!.split.map(&.to_i)
if m<2
	p 0
else
	r1=dfs(n,w,0,0,1,m)
	r2=dfs(n,w,1,1,1,m-1)
	p r1>r2 ? r1 : r2
end
0