結果

問題 No.3 ビットすごろく
ユーザー こまるこまる
提出日時 2020-10-15 21:22:38
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 851 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 150,916 KB
最終ジャッジ日時 2024-04-27 05:01:41
合計ジャッジ時間 1,141 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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:2:1: error: [GHC-87110]
    Could not load module ‘Data.IntSet’.
    It is a member of the hidden package ‘containers-0.6.8’.
    Use -v to see a list of the files searched for.
  |
2 | import           Data.IntSet                 (IntSet)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:3:1: error: [GHC-87110]
    Could not load module ‘Data.IntSet’.
    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 qualified Data.IntSet                 as IntSet
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import           Data.Bits                   (Bits(popCount))
import           Data.IntSet                 (IntSet)
import qualified Data.IntSet                 as IntSet
import qualified Data.Vector.Unboxed         as VU

popCountVector :: Int -> VU.Vector Int
popCountVector n = VU.generate (n + 1) (\i -> popCount i)
{-# NOINLINE popCountVector #-}

main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ bfs [1] [] n 1 IntSet.empty (popCountVector n)

bfs :: [Int] -> [Int] -> Int -> Int -> IntSet -> VU.Vector Int -> Int
bfs []     [] _ _ _  _   = -1
bfs []     nx g c st vec = bfs nx [] g (c + 1) st vec
bfs (b:bs) nx g c st vec
  |  b < 1
  || b > g
  || IntSet.member b st  = bfs bs nx g c st vec
  |  b == g = c
  |  otherwise
  = let
      x   = vec VU.! b
      st2 = IntSet.insert b st
    in bfs bs ((b + x) : (b - x) : nx) g c st2 vec
0