結果
| 問題 |
No.638 Sum of "not power of 2"
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-01-26 23:07:09 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 698 bytes |
| コンパイル時間 | 11,549 ms |
| コンパイル使用メモリ | 180,172 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 02:25:50 |
| 合計ジャッジ時間 | 11,941 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 |
コンパイルメッセージ
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 Control.Applicative ((<$>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Bits ((.&.))
main :: IO ()
main = do
solve <$> getl (readi B.readInt) >>= putStrLn
solve :: Int -> String
solve x = f 1 (x - 1)
where
f a b
| b == 0 = "-1"
| isp2 a || isp2 b = f (a + 1) (b - 1)
| otherwise = show a ++ " " ++ show b
isp2 :: Int -> Bool
isp2 x = f 0 x == 1
where
f c n | n == 0 = c
| otherwise = f (c + 1) (n .&. (n - 1))
getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine
readi :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> a
readi f s = let Just (n, _) = f s in n