結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
3405691582
|
| 提出日時 | 2017-03-21 02:49:09 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 2,141 ms / 5,000 ms |
| コード長 | 921 bytes |
| コンパイル時間 | 6,135 ms |
| コンパイル使用メモリ | 171,136 KB |
| 実行使用メモリ | 17,768 KB |
| 最終ジャッジ日時 | 2024-07-01 08:39:35 |
| 合計ジャッジ時間 | 31,906 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
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'+1) then [] else [(pr,b!i'+1)]
next = if nx>n || (b!nx>0&&b!nx<b!i'+1) 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 (iterate updateBoard ([1..n],board)!!(n+1)) ! n
where
board = listArray (1,n) $ 1:repeat (-1)
3405691582