結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2018-05-17 17:15:26 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 269 ms / 5,000 ms |
コード長 | 514 bytes |
コンパイル時間 | 5,599 ms |
コンパイル使用メモリ | 175,268 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 09:00:55 |
合計ジャッジ時間 | 6,130 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.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))