結果

問題 No.424 立体迷路
ユーザー ichibanshiboriichibanshibori
提出日時 2016-09-23 18:51:36
言語 F#
(F# 4.0)
結果
TLE  
実行時間 -
コード長 2,093 bytes
コンパイル時間 14,577 ms
コンパイル使用メモリ 187,472 KB
実行使用メモリ 37,924 KB
最終ジャッジ日時 2024-04-28 22:38:26
合計ジャッジ時間 20,434 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
34,688 KB
testcase_01 AC 82 ms
37,924 KB
testcase_02 AC 81 ms
31,232 KB
testcase_03 AC 83 ms
31,360 KB
testcase_04 AC 84 ms
31,232 KB
testcase_05 AC 79 ms
30,976 KB
testcase_06 AC 76 ms
30,844 KB
testcase_07 AC 81 ms
31,232 KB
testcase_08 AC 76 ms
30,844 KB
testcase_09 AC 78 ms
31,360 KB
testcase_10 AC 82 ms
30,848 KB
testcase_11 AC 81 ms
30,976 KB
testcase_12 AC 80 ms
31,088 KB
testcase_13 AC 81 ms
31,104 KB
testcase_14 AC 80 ms
31,104 KB
testcase_15 AC 81 ms
30,976 KB
testcase_16 AC 80 ms
31,088 KB
testcase_17 AC 81 ms
31,488 KB
testcase_18 AC 80 ms
30,976 KB
testcase_19 AC 80 ms
30,972 KB
testcase_20 AC 79 ms
31,064 KB
testcase_21 AC 82 ms
31,068 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (390 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/

ソースコード

diff #

open System

let () =
    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 h

    let 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 readB

    let dxy = [(1, 0); (-1, 0); (0, 1); (0, -1)]

    let searchPath startY startX =
        let canMove1 (cy, cx) (dy, dx) =
            let y = cy + dy
            let x = cx + dx

            y >= 1 && y <= w && x >= 1 && x <= h &&
            abs(mapArr.[y, x] - mapArr.[cy, cx]) <= 1

        let canMove2 (cy, cx) (dy, dx) =
            let y1, y2 = cy + dy, cy + dy * 2
            let x1, x2 = cx + dx, cx + dx * 2

            y2 >= 1 && y2 <= w && x2 >= 1 && x2 <= h &&
            mapArr.[cy, cx] = mapArr.[y2, x2] &&
            mapArr.[cy, cx] > mapArr.[y1, x1]

        let rec searchPath' lst =
            match lst with
            | [] -> false
            | x::xs ->
                let cy, cx = List.head x
                if cy = gy && cx = gx then true
                else
                    let cand1 = List.filter (canMove1 (cy, cx)) dxy
                    let cand2 = List.filter (canMove2 (cy, cx)) dxy |>
                                List.map (fun (dy, dx) -> (dy * 2, dx * 2))
                    let cand = List.append cand1 cand2
                    let candLst =
                        List.map (fun (dy, dx) -> (cy + dy, cx + dx)) cand |>
                        List.filter (fun pos -> not (List.contains pos x)) |>
                        List.map (fun pos -> pos::x)
                    let nextLst = List.append candLst xs

                    searchPath' nextLst

        searchPath' [[(startY, startX)]]

    searchPath sy sx |> (function | true -> "YES" | false -> "NO") |> printfn "%s"
0