結果
問題 | No.424 立体迷路 |
ユーザー |
|
提出日時 | 2016-09-23 22:48:39 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 469 ms / 2,000 ms |
コード長 | 2,179 bytes |
コンパイル時間 | 7,470 ms |
コンパイル使用メモリ | 187,304 KB |
実行使用メモリ | 36,096 KB |
最終ジャッジ日時 | 2024-07-05 07:09:18 |
合計ジャッジ時間 | 11,535 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (244 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 Systemlet () =let h, w = stdin.ReadLine () |>(fun l -> l.Split ()) |>(fun arr -> (int arr.[0], int arr.[1]))let sx, sy, gx, gy = stdin.ReadLine () |>(fun l -> l.Split ()) |>(fun arr -> (int arr.[0], int arr.[1],int arr.[2], int arr.[3]))let mapArr = Array2D.zeroCreateBased<int> 1 1 w hlet readB (x, line:string) =seq {1..w} |> Seq.iter (fun y -> mapArr.[y, x] <- int line.[y - 1] - int '0')seq { for y in 1..h -> (y, stdin.ReadLine ()) } |> Seq.iter readBlet searchPath startY startX =let dxy = [(1, 0); (-1, 0); (0, 1); (0, -1)]let canMove1 (cy, cx) (dy, dx) =let y, x = cy + dy, cx + dxy >= 1 && y <= w && x >= 1 && x <= h &&abs(mapArr.[y, x] - mapArr.[cy, cx]) <= 1let canMove2 (cy, cx) (dy, dx) =let y1, y2 = cy + dy, cy + dy * 2let x1, x2 = cx + dx, cx + dx * 2y2 >= 1 && y2 <= w && x2 >= 1 && x2 <= h &&mapArr.[cy, cx] = mapArr.[y2, x2] &&mapArr.[cy, cx] > mapArr.[y1, x1]let rec searchPath' lst chkedLst =match lst with| [] -> false| x::xs ->let cy, cx = xif cy = gy && cx = gx then trueelselet cand1 = List.filter (canMove1 (cy, cx)) dxylet cand2 = List.filter (canMove2 (cy, cx)) dxy |>List.map (fun (dy, dx) -> (dy * 2, dx * 2))let cand = List.append cand1 cand2let candLst =List.map (fun (dy, dx) -> (cy + dy, cx + dx)) cand |>List.filter (fun pos -> not (List.contains pos chkedLst))let nextLst = List.append candLst xslet nextChkedLst = (cy, cx) :: chkedLstsearchPath' nextLst nextChkedLstsearchPath' [(startY, startX)] []searchPath sy sx |> (function | true -> "YES" | false -> "NO") |> printfn "%s"