結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
30,440 KB
testcase_01 AC 78 ms
15,220 KB
testcase_02 AC 78 ms
15,216 KB
testcase_03 AC 79 ms
15,152 KB
testcase_04 AC 852 ms
15,328 KB
testcase_05 AC 107 ms
15,180 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 904 ms
15,280 KB
testcase_09 AC 1,056 ms
15,260 KB
testcase_10 AC 914 ms
15,216 KB
testcase_11 AC 1,088 ms
15,276 KB
testcase_12 AC 81 ms
15,296 KB
testcase_13 AC 81 ms
15,220 KB
testcase_14 RE -
testcase_15 AC 81 ms
15,120 KB
testcase_16 AC 79 ms
15,252 KB
testcase_17 AC 79 ms
15,144 KB
testcase_18 AC 80 ms
15,048 KB
testcase_19 RE -
testcase_20 AC 79 ms
15,168 KB
testcase_21 AC 80 ms
15,184 KB
testcase_22 RE -
testcase_23 AC 79 ms
15,052 KB
testcase_24 AC 80 ms
15,144 KB
testcase_25 WA -
testcase_26 AC 79 ms
15,168 KB
testcase_27 WA -
testcase_28 RE -
testcase_29 AC 79 ms
15,044 KB
testcase_30 AC 79 ms
15,104 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 TLE -
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

z = [true] * N

ans = W.inject(:+)

sel = N

bans = nil

loop {
    
    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?
        bans = ans
    elsif bans == ans
        break
    end
    
    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] = true
        ans += cst
        sel += 1
    end

}

puts ans

        

0