結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-15 21:22:38 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 851 bytes |
| コンパイル時間 | 176 ms |
| コンパイル使用メモリ | 150,784 KB |
| 最終ジャッジ日時 | 2024-11-15 05:01:34 |
| 合計ジャッジ時間 | 626 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
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