結果

問題 No.751 Frac #2
ユーザー ducktail
提出日時 2018-11-09 22:11:03
言語 Haskell
(9.10.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 526 bytes
コンパイル時間 4,839 ms
コンパイル使用メモリ 175,744 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-21 06:01:51
合計ジャッジ時間 6,018 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

import Control.Applicative
import Data.List
import Data.Ratio

main :: IO ()
main = solve <$> (getLine >> f) <*> (getLine >> f) >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> [Int] -> String
solve (a:as) bs = let n = foldl' (\x y -> x * (1 % y)) (a % 1) as
                      (b':bs') = reverse bs
                      d = foldl' (\x y -> recip x * (y % 1)) (b' % 1) bs'
                      ans = n * recip d
                      in unwords . map show $ [numerator ans, denominator ans]
0