結果

問題 No.424 立体迷路
ユーザー ducktailducktail
提出日時 2018-06-01 14:12:35
言語 Haskell
(9.8.2)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 8,817 ms
コンパイル使用メモリ 192,280 KB
実行使用メモリ 11,716 KB
最終ジャッジ日時 2023-09-18 17:05:13
合計ジャッジ時間 4,509 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,184 KB
testcase_01 AC 2 ms
7,248 KB
testcase_02 AC 3 ms
7,164 KB
testcase_03 AC 3 ms
7,276 KB
testcase_04 AC 3 ms
7,352 KB
testcase_05 AC 3 ms
7,224 KB
testcase_06 AC 3 ms
7,180 KB
testcase_07 AC 2 ms
7,264 KB
testcase_08 AC 3 ms
7,272 KB
testcase_09 AC 3 ms
7,256 KB
testcase_10 AC 3 ms
7,180 KB
testcase_11 AC 3 ms
7,312 KB
testcase_12 AC 2 ms
7,200 KB
testcase_13 AC 3 ms
7,352 KB
testcase_14 AC 3 ms
7,352 KB
testcase_15 AC 3 ms
7,280 KB
testcase_16 AC 3 ms
7,336 KB
testcase_17 AC 3 ms
8,172 KB
testcase_18 AC 4 ms
8,116 KB
testcase_19 AC 3 ms
8,108 KB
testcase_20 AC 3 ms
8,188 KB
testcase_21 AC 2 ms
7,184 KB
testcase_22 AC 3 ms
7,356 KB
testcase_23 AC 3 ms
7,188 KB
testcase_24 AC 7 ms
11,684 KB
testcase_25 AC 7 ms
11,716 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative ((<$>), (<*>))
import Control.Monad (replicateM)
import Data.Bool (bool)
import Data.List (intercalate, foldl')
import Data.Char (digitToInt)
import Data.Vector.Unboxed (Vector, (!))
import qualified Data.Vector.Unboxed as V
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [h, w] <- f
  solve h w <$> f <*> replicateM h (map digitToInt <$> getLine) >>= putStrLn
    where f = map read <$> words <$> getLine

solve :: Int -> Int -> [Int] -> [[Int]] -> String
solve h w [sx, sy, gx, gy] ms = bool "NO" "YES" . (IS.member (toIx (gx-1) (gy-1))) $ dfs w IS.empty (toIx (sx-1) (sy-1))
  where
    mv = V.fromList $ replicate (w+1) 100 ++ intercalate [100] ms ++ replicate (w+1) 100
    toIx i j = (i+1)*(w+1)+j
    dfs w mm cp = foldl' (dfs w) (IS.insert cp mm) np
      where np = [tp | tp <- [cp+1, cp-w-1, cp-1, cp+w+1], abs ((mv ! tp) - cph) <= 1, IS.notMember tp mm] ++
                 [tp2 | (tp1, tp2) <- [(cp+1, cp+2), (cp-w-1, cp-2*w-2), (cp-1, cp-2), (cp+w+1, cp+2*w+2)], (mv ! tp1) < cph, (mv ! tp2) == cph, IS.notMember tp2 mm]
            cph = mv ! cp
0