結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-03 15:43:52 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 612 bytes |
| コンパイル時間 | 338 ms |
| コンパイル使用メモリ | 148,608 KB |
| 最終ジャッジ日時 | 2024-07-01 08:40:52 |
| 合計ジャッジ時間 | 732 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / 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: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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
-- 解説、他の回答参照
import qualified Data.Set as S
import Data.Bits
solve :: S.Set Int -> S.Set Int -> Int -> Int -> Int
solve flag queue i n
| queue == S.empty = -1
| elem n queue = i
| otherwise = solve flag' queue' (i + 1) n
where
inc = S.filter (\x -> x > 0 && x <= n) $ S.map (\x -> x + popCount x) queue
dec = S.filter (\x -> x > 0 && x <= n) $ S.map (\x -> x - popCount x) queue
queue' = S.difference (S.union inc (S.difference dec inc)) flag
flag' = S.union flag queue'
main = readLn >>= print . solve (S.singleton 1) (S.singleton 1) 1