結果

問題 No.3 ビットすごろく
ユーザー 34056915823405691582
提出日時 2017-03-21 02:49:09
言語 Haskell
(9.6.2)
結果
AC  
実行時間 1,892 ms / 5,000 ms
コード長 921 bytes
コンパイル時間 3,321 ms
コンパイル使用メモリ 162,252 KB
実行使用メモリ 19,788 KB
最終ジャッジ日時 2023-09-14 00:39:18
合計ジャッジ時間 27,416 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,168 KB
testcase_01 AC 2 ms
6,992 KB
testcase_02 AC 3 ms
6,968 KB
testcase_03 AC 122 ms
16,772 KB
testcase_04 AC 12 ms
13,344 KB
testcase_05 AC 552 ms
18,684 KB
testcase_06 AC 152 ms
18,720 KB
testcase_07 AC 52 ms
16,852 KB
testcase_08 AC 363 ms
18,824 KB
testcase_09 AC 862 ms
18,752 KB
testcase_10 AC 1,242 ms
19,040 KB
testcase_11 AC 703 ms
18,472 KB
testcase_12 AC 492 ms
19,168 KB
testcase_13 AC 92 ms
15,808 KB
testcase_14 AC 1,412 ms
18,472 KB
testcase_15 AC 1,782 ms
18,956 KB
testcase_16 AC 1,562 ms
18,724 KB
testcase_17 AC 1,712 ms
19,460 KB
testcase_18 AC 72 ms
17,376 KB
testcase_19 AC 1,892 ms
19,280 KB
testcase_20 AC 12 ms
12,236 KB
testcase_21 AC 2 ms
7,048 KB
testcase_22 AC 1,382 ms
18,420 KB
testcase_23 AC 1,883 ms
19,228 KB
testcase_24 AC 1,822 ms
19,088 KB
testcase_25 AC 1,832 ms
19,200 KB
testcase_26 AC 2 ms
7,052 KB
testcase_27 AC 112 ms
19,788 KB
testcase_28 AC 1,413 ms
19,080 KB
testcase_29 AC 732 ms
18,292 KB
testcase_30 AC 3 ms
7,408 KB
testcase_31 AC 3 ms
7,568 KB
testcase_32 AC 642 ms
18,420 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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'+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)
0