結果

問題 No.3 ビットすごろく
ユーザー mazeppa1108mazeppa1108
提出日時 2015-06-03 22:16:15
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 195,212 KB
実行使用メモリ 18,024 KB
最終ジャッジ日時 2023-09-20 19:03:33
合計ジャッジ時間 6,942 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,248 KB
testcase_01 AC 3 ms
7,312 KB
testcase_02 AC 2 ms
7,340 KB
testcase_03 AC 22 ms
14,592 KB
testcase_04 AC 12 ms
13,284 KB
testcase_05 AC 82 ms
15,992 KB
testcase_06 AC 32 ms
14,500 KB
testcase_07 AC 22 ms
14,032 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 72 ms
15,236 KB
testcase_13 AC 23 ms
14,592 KB
testcase_14 AC 172 ms
16,440 KB
testcase_15 AC 262 ms
17,652 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 22 ms
14,328 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 3 ms
7,248 KB
testcase_22 AC 183 ms
16,760 KB
testcase_23 AC 282 ms
17,388 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 3 ms
7,272 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 3 ms
7,748 KB
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
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]
0