結果
問題 |
No.424 立体迷路
|
ユーザー |
|
提出日時 | 2017-01-27 20:37:28 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 7,610 ms |
コンパイル使用メモリ | 190,780 KB |
実行使用メモリ | 32,896 KB |
最終ジャッジ日時 | 2024-07-05 07:13:47 |
合計ジャッジ時間 | 9,881 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (192 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/
ソースコード
type UnionFind(n) = let n = n let parent = [| 0 .. n - 1|] member this.Parent with get() = parent member this.Find x = if this.Parent.[x] <> x then this.Parent.[x] <- this.Find this.Parent.[x] this.Parent.[x] member this.Unite x y = this.Parent.[this.Find x] <- this.Find y member this.Same x y = (this.Find x) = (this.Find y) let h, w = System.Console.ReadLine().Split() |> Array.map int |> fun a -> a.[0], a.[1] let sy, sx, gy, gx = System.Console.ReadLine().Split() |> Array.map int |> Array.map ((+) -1) |> fun a -> a.[0], a.[1], a.[2], a.[3] let b = [|for i in 0 .. h - 1 -> System.Console.ReadLine().ToCharArray() |> Array.map int|] let uf = new UnionFind(h * w) for i = 0 to h - 1 do for j = 0 to w - 1 do for di, dj in [(0, 1); (1, 0); (0, -1); (-1, 0)] do let ii = i + di let jj = j + dj if 0 <= ii && ii < h && 0 <= jj && jj < w then if abs (b.[ii].[jj] - b.[i].[j]) <= 1 then uf.Unite (i * w + j) (ii * w + jj) for di, dj in [(0, 1); (1, 0); (0, -1); (-1, 0)] do let ii = i + di let jj = j + dj let iii = i + di * 2 let jjj = j + dj * 2 if 0 <= iii && iii < h && 0 <= jjj && jjj < w then if b.[ii].[jj] < b.[i].[j] && b.[iii].[jjj] = b.[i].[j] then uf.Unite (i * w + j) (iii * w + jjj) if uf.Same (sy * w + sx) (gy * w + gx) then "YES" else "NO" |> System.Console.WriteLine