結果

問題 No.3 ビットすごろく
ユーザー 34056915823405691582
提出日時 2017-03-21 00:02:41
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 966 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 164,280 KB
実行使用メモリ 16,272 KB
最終ジャッジ日時 2023-09-18 13:27:30
合計ジャッジ時間 18,864 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,992 KB
testcase_01 AC 3 ms
6,980 KB
testcase_02 AC 2 ms
6,964 KB
testcase_03 AC 82 ms
14,404 KB
testcase_04 WA -
testcase_05 AC 373 ms
13,852 KB
testcase_06 AC 102 ms
14,660 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 353 ms
14,480 KB
testcase_13 AC 62 ms
14,404 KB
testcase_14 AC 842 ms
13,164 KB
testcase_15 AC 1,342 ms
14,144 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 3 ms
7,020 KB
testcase_22 AC 852 ms
14,244 KB
testcase_23 AC 1,353 ms
15,096 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 3 ms
6,956 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) -> ([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)
0