結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
15,252 KB
testcase_01 AC 70 ms
15,092 KB
testcase_02 AC 76 ms
15,268 KB
testcase_03 AC 70 ms
15,256 KB
testcase_04 AC 1,337 ms
15,184 KB
testcase_05 AC 125 ms
15,168 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,376 ms
15,064 KB
testcase_09 AC 1,573 ms
15,064 KB
testcase_10 AC 1,415 ms
15,176 KB
testcase_11 AC 1,605 ms
15,080 KB
testcase_12 AC 76 ms
15,356 KB
testcase_13 AC 72 ms
15,108 KB
testcase_14 AC 72 ms
15,240 KB
testcase_15 AC 69 ms
15,040 KB
testcase_16 AC 68 ms
15,264 KB
testcase_17 AC 70 ms
15,108 KB
testcase_18 AC 72 ms
15,016 KB
testcase_19 AC 75 ms
15,236 KB
testcase_20 AC 71 ms
15,064 KB
testcase_21 AC 72 ms
15,124 KB
testcase_22 AC 73 ms
15,116 KB
testcase_23 AC 71 ms
15,084 KB
testcase_24 AC 69 ms
15,200 KB
testcase_25 WA -
testcase_26 AC 69 ms
15,012 KB
testcase_27 WA -
testcase_28 AC 73 ms
15,264 KB
testcase_29 AC 72 ms
15,248 KB
testcase_30 AC 72 ms
15,092 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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[kk]
        kk = (kk + 1) % N
    end
    z[kk] = true
    ans += W[kk - 1] if z[kk - 1]
    ans += W[kk] if z[(kk + 1) % N]
    sel += 1
    
}

puts bans

        

0