結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2015-03-09 08:05:18 |
言語 | Haskell (9.10.1) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 544 bytes |
コンパイル時間 | 7,828 ms |
コンパイル使用メモリ | 171,648 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2024-06-24 16:47:07 |
合計ジャッジ時間 | 14,364 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 RE * 1 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Control.Applicative import Data.List import Data.Bits (popCount) solve n = (\x -> if last x == [] then -1 else 1+length x) $ unfoldr next (1,[[1]]) where next :: (Int,[[Int]]) -> Maybe ([Int],(Int,[[Int]])) next (m,h'@(h:hs)) | n `elem` h || h == [] = Nothing | otherwise = let k = nub $ h >>= flip step h' in Just (k,(m+1,k:h')) step :: Int -> [[Int]] -> [Int] step j hs = [i|i<-fmap ((j+) . (*popCount j)) [1,-1], 1<=i, i<=n, all (notElem i) hs] main = do n <- (read :: String -> Int) <$> getLine print $ solve n