結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2017-03-21 00:02:41 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 966 bytes |
コンパイル時間 | 10,860 ms |
コンパイル使用メモリ | 173,184 KB |
実行使用メモリ | 13,584 KB |
最終ジャッジ日時 | 2024-07-05 04:37:41 |
合計ジャッジ時間 | 17,206 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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) -> ([Int],Board) updateBoard ([],b) = ([],b) updateBoard (is,b) = (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 = snd (ntimes n updateBoard ([1..n],board)) ! n where board = listArray (1,n) $ 1:repeat (-1) ntimes 0 f x = x ntimes n f x = ntimes (n-1) f (f x)