結果

問題 No.324 落ちてた閉路グラフ
ユーザー maimai
提出日時 2017-05-17 09:54:16
言語 Ruby
(3.2.2)
結果
TLE  
実行時間 -
コード長 585 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 11,832 KB
実行使用メモリ 184,748 KB
最終ジャッジ日時 2023-10-17 14:40:17
合計ジャッジ時間 8,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
16,048 KB
testcase_01 AC 85 ms
16,048 KB
testcase_02 AC 85 ms
16,048 KB
testcase_03 AC 85 ms
16,048 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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def scan;gets.split.map(&:to_i);end


@n,@m = scan
@ww = scan

@memo = {}
def dfs(idx, lastflg, selected, firstflg)
    return firstflg&&lastflg ? @ww[0] : 0 if idx == @n
    key = [idx, lastflg, selected, firstflg]
    return @memo[key] if @memo[key]
    r = []
    r << ((lastflg ? @ww[idx] : 0) + dfs(idx+1, true, selected+1, firstflg)) if selected < @m
    r << (dfs(idx+1, false, selected, firstflg)) if idx - selected < @n - @m
    return @memo[key] = r.max
end

if @n == @m
    p @ww.inject(:+)
elsif @m <= 1
    p 0
else
    p [dfs(1,false,0,false),dfs(1,true,1,true)].max
end
0