結果

問題 No.20 砂漠のオアシス
ユーザー aimyaimy
提出日時 2017-06-09 13:36:34
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,252 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 150,400 KB
最終ジャッジ日時 2024-04-27 04:56:32
合計ジャッジ時間 517 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

Main.hs:3:1: error: [GHC-87110]
    Could not load module ‘Data.IntMap.Strict’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
3 | import Data.IntMap.Strict ((!))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:4:1: error: [GHC-87110]
    Could not load module ‘Data.IntMap.Strict’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
4 | import qualified Data.IntMap.Strict as M
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:5:1: error: [GHC-87110]
    Could not load module ‘Data.Set’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
5 | import qualified Data.Set as S
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Data.Bool
import Data.Char
import Data.IntMap.Strict ((!))
import qualified Data.IntMap.Strict as M
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B

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

pos n x y = (n+1)*(x-1) + (y-1)
north n p = p + (n+1)
south n p = p - (n+1)
east p = succ p
west p = pred p
inbound n p = p>=0 && p<=n*(n+1)-1 && mod p (n+1) /= n 

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

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

dp n 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 - digitToInt (B.index g w)) acc) q' vns
  vns = filter (inbound n) (sequence [north n, south n, east, west] v)
0