結果

問題 No.324 落ちてた閉路グラフ
ユーザー LeonardoneLeonardone
提出日時 2015-12-17 01:00:14
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 1,705 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 11,468 KB
実行使用メモリ 21,148 KB
最終ジャッジ日時 2023-10-14 11:51:33
合計ジャッジ時間 7,919 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,140 KB
testcase_01 AC 76 ms
15,244 KB
testcase_02 AC 75 ms
15,160 KB
testcase_03 AC 76 ms
15,272 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 #

#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

def gs() gets.chomp end
def gi() gets.to_i end
def gss() gets.chomp.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j|pr.call(i,j)}} end


$N, $M = gis
$W = gis

if $M < 2
    puts 0
    exit
end

$minselln = $M * 2 > $N ? $M * 2 - $N : 0
$maxselln = $M - 1

$ans = $M * 2 > $N ? $W.take($M * 2 - $N).inject(:+) : 0

$ar = [true] * $N
$v = 0
$ln = 0
$vt = 0

def f(s)
    if $vt > $M
        return
    end
    if $vt == $M
        $ans = [$ans, $v].max
    end
    (s...$N).each do |i|
        if $ar[i]
            $ar[i] = false
            avt = 2
            c1 = false
            if !$ar[i - 1]
                avt -= 1
            elsif !$ar[i - 2]
                c1 = true
                $ar[i - 1] = false
                $v += $W[i - 1]
            end
            c2 = false
            if !$ar[(i + 1) % $N]
                avt -= 1
            elsif !$ar[(i + 2) % $N]
                c2 = true
                $ar[(i + 1) % $N] = false
                $v += $W[(i + 1) % $N]
            end
            $v += $W[i]
            $vt += avt
            f(i + 1)
            $vt -= avt
            if c1
                $v -= $W[i - 1]
                $ar[i - 1] = true
            end
            if c2
                $v -= $W[(i + 1) % $N]
                $ar[(i + 1) % $N] = true
            end
            $v -= $W[i]
            $ar[i] = true
        end
    end
end

f(0)

puts $ans
0