結果

問題 No.638 Sum of "not power of 2"
ユーザー ducktailducktail
提出日時 2018-01-26 23:07:09
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 698 bytes
コンパイル時間 9,441 ms
コンパイル使用メモリ 162,056 KB
実行使用メモリ 7,456 KB
最終ジャッジ日時 2023-08-28 18:11:58
合計ジャッジ時間 9,749 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,296 KB
testcase_01 AC 2 ms
7,416 KB
testcase_02 AC 3 ms
7,344 KB
testcase_03 AC 2 ms
7,380 KB
testcase_04 AC 2 ms
7,420 KB
testcase_05 AC 2 ms
7,388 KB
testcase_06 AC 3 ms
7,392 KB
testcase_07 AC 3 ms
7,348 KB
testcase_08 AC 3 ms
7,456 KB
testcase_09 AC 3 ms
7,384 KB
testcase_10 AC 3 ms
7,380 KB
testcase_11 AC 2 ms
7,456 KB
testcase_12 AC 2 ms
7,376 KB
testcase_13 AC 2 ms
7,380 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 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
0