結果

問題 No.17 2つの地点に泊まりたい
ユーザー gigurururugigurururu
提出日時 2014-12-31 14:22:48
言語 Ruby
(3.3.0)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 464 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-23 02:00:39
合計ジャッジ時間 3,282 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
12,288 KB
testcase_01 AC 77 ms
12,288 KB
testcase_02 AC 82 ms
12,160 KB
testcase_03 AC 85 ms
12,160 KB
testcase_04 AC 81 ms
12,416 KB
testcase_05 AC 104 ms
12,544 KB
testcase_06 AC 99 ms
12,416 KB
testcase_07 AC 91 ms
12,288 KB
testcase_08 AC 111 ms
12,672 KB
testcase_09 AC 120 ms
12,672 KB
testcase_10 AC 86 ms
12,544 KB
testcase_11 AC 83 ms
12,416 KB
testcase_12 AC 74 ms
12,160 KB
testcase_13 AC 76 ms
12,032 KB
testcase_14 AC 77 ms
12,160 KB
testcase_15 AC 75 ms
12,288 KB
testcase_16 AC 75 ms
12,160 KB
testcase_17 AC 80 ms
12,288 KB
testcase_18 AC 93 ms
12,416 KB
testcase_19 AC 81 ms
12,032 KB
testcase_20 AC 87 ms
12,288 KB
testcase_21 AC 77 ms
12,160 KB
testcase_22 AC 81 ms
12,160 KB
testcase_23 AC 103 ms
12,416 KB
testcase_24 AC 99 ms
12,416 KB
testcase_25 AC 77 ms
12,288 KB
testcase_26 AC 101 ms
12,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

s=(1..n=gets.to_i).map{gets.to_i}
c=(1..n).map{{}}
gets.to_i.times{
  a,b,d=gets.split.map(&:to_i)
  c[a][b]=c[b][a]=d
}
q=[[0,0,[0,n-1]],[1e9]]
gn={}
while q[0]&&(q[0][1]<n-1||q[0][2].size<4)
  cost,cur,st=q.shift
  next if gn[[cur,st]]
  gn[[cur,st]]=1
  ad=(st.size<4&&!st.include?(cur))?[[cost+s[cur],cur,(st+[cur]).sort]]:[]
  c[cur].each{|k,v|ad<<[cost+v,k,st]}
  ad.each{|i|q.insert((0..q.size).bsearch{|j|q[j][0]>=i[0]},i)if !gn[[i[1],i[2]]]}
end
p q[0][0]
0