結果
| 問題 |
No.324 落ちてた閉路グラフ
|
| ユーザー |
|
| 提出日時 | 2015-12-17 02:36:14 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,456 bytes |
| コンパイル時間 | 188 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,544 KB |
| 最終ジャッジ日時 | 2024-09-16 06:59:03 |
| 合計ジャッジ時間 | 11,182 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 20 WA * 11 RE * 3 |
コンパイルメッセージ
Syntax OK
ソースコード
#! 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
sel = N
bans = nil
20.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 sel < M + 2
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 bans