結果

問題 No.3 ビットすごろく
ユーザー 34056915823405691582
提出日時 2017-03-20 23:55:51
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 906 bytes
コンパイル時間 11,807 ms
コンパイル使用メモリ 163,124 KB
実行使用メモリ 16,100 KB
最終ジャッジ日時 2023-09-18 13:27:04
合計ジャッジ時間 27,540 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,820 KB
testcase_01 AC 3 ms
6,836 KB
testcase_02 AC 2 ms
6,808 KB
testcase_03 AC 72 ms
14,204 KB
testcase_04 WA -
testcase_05 AC 322 ms
13,724 KB
testcase_06 AC 82 ms
14,580 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 313 ms
13,776 KB
testcase_13 AC 52 ms
14,192 KB
testcase_14 AC 742 ms
13,164 KB
testcase_15 AC 1,193 ms
13,952 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
6,836 KB
testcase_22 AC 772 ms
12,956 KB
testcase_23 AC 1,233 ms
14,688 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,776 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
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.Array
type Board = Array Int Int
main = do
  n <- read <$> getLine :: IO Int
  putStrLn $ show $ calcMinDist n

updateBoard :: [Int] -> Board -> [Board]
updateBoard [] b = repeat b
updateBoard is b =
  b:updateBoard is' (b//if b!i'<0 then [] else prev ++ next)
  where
    (_,n) = bounds b
    numOfOne = sum . map (`mod`2) . takeWhile (>0) . iterate (`div`2)
    pr = i' - numOfOne i'
    nx = i' + numOfOne i'
    prev = if pr<1 || (b!pr>=0&&b!pr<b!i') then [] else [(pr,b!i'+1)]
    next = if nx>n || (b!nx>=0&&b!nx<b!i') then [] else [(nx,b!i'+1)]
    (i',is') = findMinDistInd is
    findMinDistInd [i] = (i,[])
    findMinDistInd (i:is) =
      let (i',is') = findMinDistInd is in
        if b!i'<0 || (b!i>=0 && b!i<=b!i') then (i,i':is') else (i',i:is')

calcMinDist :: Int -> Int
calcMinDist n =
  (updateBoard [1..n] board !! n) ! n
  where
    board = listArray (1,n) $ 1:repeat (-1)
0