結果

問題 No.3 ビットすごろく
コンテスト
ユーザー 3405691582
提出日時 2017-03-20 23:55:51
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 906 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,677 ms
コンパイル使用メモリ 192,768 KB
実行使用メモリ 15,784 KB
最終ジャッジ日時 2026-03-26 11:15:13
合計ジャッジ時間 19,826 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

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