結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2016-07-16 23:05:13 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 111 ms / 5,000 ms |
コード長 | 848 bytes |
コンパイル時間 | 95 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,160 KB |
最終ジャッジ日時 | 2024-10-15 01:35:28 |
合計ジャッジ時間 | 3,460 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
Syntax OK
ソースコード
INF = 1000000000000000n = gets.to_istay = Array.new(n)n.times{ |i|stay[i] = gets.to_i}m = gets.to_idist = Array.new(n)dp = Array.new(n)n.times{|i|dist[i] = Array.new(n, INF)dp[i] = Array.new(n, INF)}m.times{|i|a, b, c = gets.strip.split.map{|e| e.to_i}dist[a][b] = cdist[b][a] = c}# 初期化for i in (0...n)for j in (0...n)if i == jdp[i][j] = 0elsedp[i][j] = dist[i][j]endendend# 2地点間の最短経路(ワーシャルフロイド)for k in (0...n)for i in (0...n)for j in (0...n)dp[i][j] = [dp[i][j], dp[i][k] + dp[k][j]].minendendendcost = INF# 宿泊地2つを全探索するfor i in (1...n-1)for j in (1...n-1)if i != jcost = [cost, dp[0][i] + stay[i] + dp[i][j] + stay[j] + dp[j][n-1]].minendendendputs cost