結果

問題 No.20 砂漠のオアシス
ユーザー aimyaimy
提出日時 2017-05-27 16:00:50
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,177 bytes
コンパイル時間 3,026 ms
コンパイル使用メモリ 141,952 KB
最終ジャッジ日時 2023-11-20 21:48:57
合計ジャッジ時間 3,679 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:2:1: error:
    Could not load module ‘Data.IntMap.Strict’
    It is a member of the hidden package ‘containers-0.6.7’.
    You can run ‘:set -package containers’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
2 | import Data.IntMap.Strict ((!))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:3:1: error:
    Could not load module ‘Data.IntMap.Strict’
    It is a member of the hidden package ‘containers-0.6.7’.
    You can run ‘:set -package containers’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
3 | import qualified Data.IntMap.Strict as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:4:1: error:
    Could not load module ‘Data.Set’
    It is a member of the hidden package ‘containers-0.6.7’.
    You can run ‘:set -package containers’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import qualified Data.Set as S
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Data.Bool
import Data.IntMap.Strict ((!))
import qualified Data.IntMap.Strict as M
import qualified Data.Set as S

type Vertex = Int
type Cost = Int

type Heap = S.Set (Cost, Vertex)
nullq = S.null
empty = S.empty 
push v c = S.insert (c,v)
pop = S.deleteFindMax

modulo = 1000
pos x y = modulo*x + y
north p = p - modulo
south p = p + modulo
east p = succ p
west p = pred p

main = do
 [n,v,ox,oy] <- map read . words <$> getLine
 ls <- map read . words <$> getContents
 putStrLn (bool "NO" "YES" (oasys n v ox oy ls))

oasys n v ox oy ls = M.member pds im1 || ((M.member po im1) && (M.member pds im2))
 where
  (im1,_) = until (nullq . snd) (dp g) (im0,q0)
  (im2,_) = until (nullq . snd) (dp g) (im0,q1)
  pdp = pos 1 1
  pds = pos n n
  po = pos oy ox
  g = M.fromDistinctAscList (zip [pos x y | x<-[1..n], y<-[1..n]] ls)
  im0 = M.empty
  q0 = push pdp v empty
  q1 = push po ((im1!po)*2) empty

dp g (im,q)
 | h < 1 = (im,q')
 | M.member v im = (im,q')
 | otherwise = (im',q'')
 where
  ((h,v),q') = pop q
  im' = M.insertWith max v h im
  q'' = foldr (\w acc -> push w (h-(g!w)) acc) q' vns
  vns = filter (\w -> M.member w g) (sequence [north,south,east,west] v)
0