結果

問題 No.3 ビットすごろく
ユーザー e7a894e7a894
提出日時 2018-05-17 17:15:26
言語 Haskell
(9.8.2)
結果
AC  
実行時間 303 ms / 5,000 ms
コード長 514 bytes
コンパイル時間 6,657 ms
コンパイル使用メモリ 166,036 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-09-14 01:00:32
合計ジャッジ時間 5,921 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,844 KB
testcase_01 AC 2 ms
6,892 KB
testcase_02 AC 3 ms
6,948 KB
testcase_03 AC 22 ms
7,216 KB
testcase_04 AC 4 ms
7,100 KB
testcase_05 AC 92 ms
7,688 KB
testcase_06 AC 32 ms
7,188 KB
testcase_07 AC 12 ms
7,124 KB
testcase_08 AC 62 ms
7,464 KB
testcase_09 AC 142 ms
7,760 KB
testcase_10 AC 202 ms
7,944 KB
testcase_11 AC 122 ms
7,804 KB
testcase_12 AC 82 ms
7,628 KB
testcase_13 AC 22 ms
7,140 KB
testcase_14 AC 192 ms
7,944 KB
testcase_15 AC 303 ms
8,320 KB
testcase_16 AC 262 ms
8,196 KB
testcase_17 AC 292 ms
8,164 KB
testcase_18 AC 22 ms
7,216 KB
testcase_19 AC 302 ms
8,204 KB
testcase_20 AC 3 ms
7,084 KB
testcase_21 AC 3 ms
6,736 KB
testcase_22 AC 202 ms
7,896 KB
testcase_23 AC 302 ms
8,248 KB
testcase_24 AC 302 ms
8,288 KB
testcase_25 AC 292 ms
8,152 KB
testcase_26 AC 2 ms
6,872 KB
testcase_27 AC 22 ms
7,356 KB
testcase_28 AC 242 ms
8,036 KB
testcase_29 AC 132 ms
7,772 KB
testcase_30 AC 2 ms
7,136 KB
testcase_31 AC 2 ms
6,984 KB
testcase_32 AC 102 ms
7,640 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.Bits

main = do
  n <- readLn :: IO Int
  putStrLn . show $ resolve n

resolve :: Int -> Int
resolve n = resolve' [1] [] [] 1
  where
    resolve' [] [] _ _ = -1
    resolve' [] nx sd c = resolve' nx [] sd (c + 1)
    resolve' (t:ts) nx sd c
      | t == n = c
      | t `elem` sd || t > n = resolve' ts nx sd c
      | otherwise = resolve' ts ((t + bitCnt t):(t - bitCnt t):nx) (t:sd) c

bitCnt :: Int -> Int
bitCnt 0 = 0
bitCnt n
  | n > 10000 || n == 0 = 0
  | otherwise = 1 + bitCnt (n .&. (n - 1))
0