結果

問題 No.324 落ちてた閉路グラフ
ユーザー kura07kura07
提出日時 2015-12-17 12:03:11
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 722 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 11,412 KB
実行使用メモリ 54,684 KB
最終ジャッジ日時 2023-10-14 12:37:54
合計ジャッジ時間 10,025 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
19,708 KB
testcase_01 AC 83 ms
15,140 KB
testcase_02 AC 81 ms
15,216 KB
testcase_03 AC 84 ms
15,076 KB
testcase_04 AC 2,328 ms
51,628 KB
testcase_05 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, m = gets.split.map(&:to_i)
ws = gets.split.map(&:to_i)
memo = Array.new(2){ Array.new(2){ Array.new(2){ Array.new(m+1, -Float::INFINITY) } } }

memo[0][0][0][m] = 0
memo[0][1][1][m-1] = 0
0.upto(n-2){|i|
	0.upto(m){|j|
		memo[1][0][0][j] = [memo[0][0][0][j], memo[0][0][1][j]].max
		memo[1][0][1][j] = [memo[0][0][0][j+1], memo[0][0][1][j+1] + ws[i]].max if j < m
		memo[1][1][0][j] = [memo[0][1][0][j], memo[0][1][1][j]].max
		memo[1][1][1][j] = [memo[0][1][0][j+1], memo[0][1][1][j+1] + ws[i]].max if j < m
	}
	memo[0] = memo[1]
	memo[1] = Array.new(2){ Array.new(2){ Array.new(m+1, -Float::INFINITY) } }
}

memo[0][1][1][0] += ws.last
puts [memo[0][0][0][0], memo[0][0][1][0], memo[0][1][0][0], memo[0][1][1][0]].max
0