結果
問題 | No.17 2つの地点に泊まりたい |
ユーザー |
![]() |
提出日時 | 2018-04-10 00:59:10 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 357 ms / 5,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 15,689 ms |
コンパイル使用メモリ | 199,972 KB |
実行使用メモリ | 36,132 KB |
最終ジャッジ日時 | 2024-10-15 04:08:54 |
合計ジャッジ時間 | 26,442 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (320 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
open System open System.Collections.Generic type WarshallFloyd(n,?isNonDir0:bool)= let isNonDir = defaultArg isNonDir0 true let inf = 1e16|>int64 let vertexNum = n let edgeNum = ref 0 let costs = Array2D.init<int64> (n+1) (n+1) (fun i j-> if i <> j then inf else 0L) member this.Inf = inf member this.AddPath f t c = incr edgeNum costs.[f,t]<-min costs.[f,t] c if isNonDir then costs.[t,f]<-min costs.[t,f] c member this.Run() = for i in 0..vertexNum do for j in 0..vertexNum do for k in 0..vertexNum do costs.[j,k]<-min costs.[j,k] (costs.[j,i]+costs.[i,k]) member this.PathExist f t = costs.[f,t] <> inf member this.MinCosts() = costs member this.MinCost f t = costs.[f,t] let read() = Console.ReadLine() let N = read() |> int let ws = WarshallFloyd(N) let S = Array.init N (fun _ -> read() |> int64) let M = read() |> int for i in 0..M-1 do let t = read().Split() ws.AddPath (t.[0] |> int) (t.[1] |> int) (t.[2] |> int64) ws.Run() [for i in [1..N-2] do for j in [1..N-2] do if i <> j then yield (i,j)] |> List.map (fun (a,b) -> (ws.MinCost 0 a) + S.[a] + (ws.MinCost a b) + S.[b] + (ws.MinCost b (N-1))) |> List.min |> printfn "%i"