結果

問題 No.3 ビットすごろく
ユーザー こまるこまる
提出日時 2020-10-15 21:30:56
言語 Haskell
(9.8.2)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 841 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 201,100 KB
実行使用メモリ 10,728 KB
最終ジャッジ日時 2023-09-14 01:53:17
合計ジャッジ時間 2,687 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,336 KB
testcase_01 AC 2 ms
7,492 KB
testcase_02 AC 2 ms
7,468 KB
testcase_03 AC 3 ms
8,052 KB
testcase_04 AC 3 ms
7,584 KB
testcase_05 AC 4 ms
9,156 KB
testcase_06 AC 3 ms
8,132 KB
testcase_07 AC 3 ms
7,820 KB
testcase_08 AC 4 ms
8,608 KB
testcase_09 AC 5 ms
9,476 KB
testcase_10 AC 5 ms
10,020 KB
testcase_11 AC 5 ms
9,380 KB
testcase_12 AC 4 ms
9,048 KB
testcase_13 AC 3 ms
7,996 KB
testcase_14 AC 5 ms
9,876 KB
testcase_15 AC 6 ms
10,576 KB
testcase_16 AC 5 ms
10,316 KB
testcase_17 AC 6 ms
10,440 KB
testcase_18 AC 3 ms
7,912 KB
testcase_19 AC 6 ms
10,636 KB
testcase_20 AC 3 ms
7,616 KB
testcase_21 AC 3 ms
7,312 KB
testcase_22 AC 5 ms
9,912 KB
testcase_23 AC 6 ms
10,560 KB
testcase_24 AC 6 ms
10,728 KB
testcase_25 AC 6 ms
10,512 KB
testcase_26 AC 3 ms
7,240 KB
testcase_27 AC 3 ms
8,080 KB
testcase_28 AC 5 ms
10,236 KB
testcase_29 AC 5 ms
9,388 KB
testcase_30 AC 3 ms
7,464 KB
testcase_31 AC 3 ms
7,448 KB
testcase_32 AC 4 ms
9,172 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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                   (Bits(popCount))
import           Data.IntSet                 (IntSet)
import qualified Data.IntSet                 as IntSet
import qualified Data.Vector.Unboxed         as VU

popCountVector :: Int -> VU.Vector Int
popCountVector n = VU.generate (n + 1) popCount
{-# NOINLINE popCountVector #-}

main :: IO ()
main = do
  n <- readLn :: IO Int
  print $ bfs [1] [] n 1 IntSet.empty (popCountVector n)

bfs :: [Int] -> [Int] -> Int -> Int -> IntSet -> VU.Vector Int -> Int
bfs []     [] _ _ _  _   = -1
bfs []     nx g c st vec = bfs nx [] g (c + 1) st vec
bfs (b:bs) nx g c st vec
  |  b < 1
  || b > g
  || IntSet.member b st  = bfs bs nx g c st vec
  |  b == g = c
  |  otherwise
  = let
      x   = vec VU.! b
      st2 = IntSet.insert b st
    in bfs bs ((b + x) : (b - x) : nx) g c st2 vec
0