結果

問題 No.219 巨大数の概算
ユーザー ducktailducktail
提出日時 2018-09-14 16:11:56
言語 Haskell
(9.8.2)
結果
AC  
実行時間 123 ms / 1,500 ms
コード長 820 bytes
コンパイル時間 6,984 ms
コンパイル使用メモリ 163,552 KB
実行使用メモリ 23,104 KB
最終ジャッジ日時 2023-09-19 05:47:38
合計ジャッジ時間 17,150 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
22,564 KB
testcase_01 AC 112 ms
22,520 KB
testcase_02 AC 122 ms
22,624 KB
testcase_03 AC 112 ms
22,520 KB
testcase_04 AC 112 ms
23,104 KB
testcase_05 AC 3 ms
7,040 KB
testcase_06 AC 23 ms
11,948 KB
testcase_07 AC 3 ms
6,928 KB
testcase_08 AC 22 ms
12,092 KB
testcase_09 AC 3 ms
6,964 KB
testcase_10 AC 112 ms
22,556 KB
testcase_11 AC 123 ms
22,468 KB
testcase_12 AC 123 ms
22,508 KB
testcase_13 AC 122 ms
22,508 KB
testcase_14 AC 113 ms
22,560 KB
testcase_15 AC 112 ms
22,548 KB
testcase_16 AC 113 ms
22,688 KB
testcase_17 AC 113 ms
22,552 KB
testcase_18 AC 113 ms
22,520 KB
testcase_19 AC 111 ms
22,576 KB
testcase_20 AC 123 ms
22,564 KB
testcase_21 AC 113 ms
22,524 KB
testcase_22 AC 122 ms
22,544 KB
testcase_23 AC 122 ms
22,616 KB
testcase_24 AC 123 ms
22,524 KB
testcase_25 AC 112 ms
22,548 KB
testcase_26 AC 113 ms
22,624 KB
testcase_27 AC 112 ms
22,548 KB
testcase_28 AC 123 ms
22,476 KB
testcase_29 AC 113 ms
22,536 KB
testcase_30 AC 113 ms
22,616 KB
testcase_31 AC 122 ms
22,560 KB
testcase_32 AC 112 ms
22,508 KB
testcase_33 AC 122 ms
22,600 KB
testcase_34 AC 122 ms
22,568 KB
testcase_35 AC 123 ms
22,564 KB
testcase_36 AC 112 ms
22,456 KB
testcase_37 AC 112 ms
22,560 KB
testcase_38 AC 112 ms
22,460 KB
testcase_39 AC 112 ms
22,456 KB
testcase_40 AC 112 ms
22,620 KB
testcase_41 AC 113 ms
22,540 KB
testcase_42 AC 113 ms
22,460 KB
testcase_43 AC 113 ms
22,548 KB
testcase_44 AC 112 ms
22,456 KB
testcase_45 AC 113 ms
22,608 KB
testcase_46 AC 112 ms
22,548 KB
testcase_47 AC 112 ms
22,564 KB
testcase_48 AC 112 ms
22,568 KB
testcase_49 AC 113 ms
22,560 KB
testcase_50 AC 112 ms
22,552 KB
testcase_51 AC 3 ms
7,148 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 Control.Monad

main :: IO ()
main = do
  n <- readLn
  map solve <$> replicateM n f >>= mapM_ putStrLn
  where
    -- f = readi B.readInt <$> B.getLine
    f = map read <$> words <$> getLine

solve :: [Int] -> String
solve [a, b] = unwords . map show $ let x = pow b in [truncate . fst $ x, flip mod 10 . truncate . (* 10) . fst $ x, snd x]
  where
    pow :: Int -> (Double, Int)
    pow 1 = norm (fromIntegral a, 0)
    pow n
      | even n = let x = pow (n `div` 2) in mul x x
      | otherwise = let x = pow (n `div` 2) in mul (mul x x) (pow 1)
    mul :: (Double, Int) -> (Double, Int) -> (Double, Int)
    mul (x1, y1) (x2, y2) = norm (x1 * x2, y1 + y2)
    norm :: (Double, Int) -> (Double, Int)
    norm (x, y)
      | x < 10.0 = (x, y)
      | otherwise = norm (x / 10.0, y+1)
0