結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2015-06-03 22:16:15 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,004 bytes |
コンパイル時間 | 9,187 ms |
コンパイル使用メモリ | 201,344 KB |
実行使用メモリ | 15,684 KB |
最終ジャッジ日時 | 2024-07-06 14:00:03 |
合計ジャッジ時間 | 12,854 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
コンパイルメッセージ
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 Data.Bits import Control.Monad.State import qualified Data.Vector.Unboxed as U import Debug.Trace main = do n <- readLn print . (\x -> case x of [] -> -1 _ -> minimum x) $ evalState (bitDice 1 n) (1, U.fromList []) bitDice :: Int -> Int -> State (Int, U.Vector Int) [Int] bitDice k n = do (c, visited) <- get if k `U.elem` visited || k > n || k < 1 then return [] else if k == n then return [c] else do let nexts = [k + popCount k, k - popCount k] new_s = (c + 1, k `U.cons` visited) put new_s let (left, ls) = runState (bitDice (nexts !! 0) n) new_s put ls let (right, rs) = runState (bitDice (nexts !! 1) n) (c + 1, k `U.cons` snd ls) put rs return $ concat [left, right]