結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-03-20 23:55:51 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 906 bytes |
コンパイル時間 | 8,905 ms |
コンパイル使用メモリ | 173,252 KB |
実行使用メモリ | 13,804 KB |
最終ジャッジ日時 | 2024-07-05 04:37:10 |
合計ジャッジ時間 | 23,286 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 19 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
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)