結果

問題 No.3 ビットすごろく
ユーザー aimyaimy
提出日時 2017-04-28 09:36:44
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 653 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 149,632 KB
最終ジャッジ日時 2024-04-27 04:56:28
合計ジャッジ時間 456 ms
ジャッジサーバーID
(参考情報)
judge3 / 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:3: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.
  |
3 | import qualified Data.Set as S
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Data.List
import Data.Tuple
import qualified Data.Set as S

bitn n = sum $ take w $ unfoldr (return . swap . flip divMod 2) n
 where w = ceiling (logBase 2 (fromIntegral n)) + 1

main = readLn >>= putStrLn . maybe "-1" show . sugoroku

sugoroku n = sugoroku' 1 S.empty (S.singleton 1)
 where
  sugoroku' s acc next
   | S.null next = Nothing
   | S.member n next = Just s
   | otherwise = sugoroku' (s+1) (S.union acc next) (S.difference next' acc)
   where
    next' = S.difference (S.union adv bak) acc
    adv = S.filter (\x -> x<=n && x>0) $ S.map (\x -> x + bitn x) next
    bak = S.filter (\x -> x<=n && x>0) $ S.map (\x -> x - bitn x) next
0