結果

問題 No.3 ビットすごろく
ユーザー mazeppa1108mazeppa1108
提出日時 2015-06-03 02:10:14
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 793 bytes
コンパイル時間 8,304 ms
コンパイル使用メモリ 160,532 KB
実行使用メモリ 164,912 KB
最終ジャッジ日時 2023-09-20 18:56:04
合計ジャッジ時間 14,966 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,156 KB
testcase_01 AC 3 ms
6,980 KB
testcase_02 AC 3 ms
6,992 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.Bits
import Control.Monad.State

main = do
  n <- readLn
  print . (\x -> case x of
                  [] -> -1
                  _ -> minimum x) $ evalState (bitDice 1 n) (1, [])


bitDice :: Int -> Int -> State (Int, [Int]) [Int]
bitDice k n  = do
  (c, visited)  <- get
  if k `elem` visited
     then return []
     else if k == n
             then return [c] 
             else if k > n || k < 0
                     then return []
                     else do 
                             let
                                 new_k = filter (\x -> x > 0 && x <= n) [k + popCount k, k - popCount k]
                             put (c + 1, k : visited)
                             return . concat . map (\s -> evalState s (c + 1, k : visited)) $ map (\s -> bitDice s n) new_k
0