結果

問題 No.324 落ちてた閉路グラフ
ユーザー LeonardoneLeonardone
提出日時 2015-12-17 02:48:02
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 1,316 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 11,264 KB
実行使用メモリ 15,696 KB
最終ジャッジ日時 2023-10-14 12:13:22
合計ジャッジ時間 11,585 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 80 ms
15,180 KB
testcase_13 AC 78 ms
15,228 KB
testcase_14 AC 77 ms
15,280 KB
testcase_15 AC 76 ms
15,264 KB
testcase_16 AC 76 ms
15,032 KB
testcase_17 AC 84 ms
15,144 KB
testcase_18 AC 76 ms
15,324 KB
testcase_19 AC 76 ms
15,192 KB
testcase_20 AC 77 ms
15,116 KB
testcase_21 RE -
testcase_22 AC 76 ms
15,132 KB
testcase_23 AC 75 ms
15,292 KB
testcase_24 AC 75 ms
15,132 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 74 ms
15,148 KB
testcase_29 AC 75 ms
15,120 KB
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:42: warning: assigned but unused variable - kk
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

z = [true] * N

ans = W.inject(:+)

if N == M
    puts ans
    exit
end

if N - M == 1
    puts (ans - W.rotate(-1).zip(W).map{|x,y|x+y}.min)
    exit
end

sel = N

bans = nil
kk = 0

(N - M).times {
    
    while sel > M
        j = nil
        cst = nil
        N.times do |i|
            next if !z[i]
            tmp = 0
            tmp += W[i - 1] if z[i - 1]
            tmp += W[i] if z[(i + 1) % N]
            if j.nil? || tmp < cst
                j = i
                cst = tmp
            end
        end
        z[j] = false
        ans -= cst
        sel -= 1
    end
    
    if bans.nil? || ans > bans
        bans = ans
    end
    
    while z[k]
        k = (k + 1) % N
    end
    z[k] = true
    ans += W[k - 1] if z[k - 1]
    ans += W[k] if z[(k + 1) % N]
    sel += 1
    
}

puts bans

        

0