結果

問題 No.81 すべて足すだけの簡単なお仕事です。
コンテスト
ユーザー trineutron
提出日時 2020-04-09 02:04:50
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 819 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,122 ms
コンパイル使用メモリ 192,112 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-03 10:06:48
合計ジャッジ時間 9,569 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
Main.hs:15:7: warning: [GHC-63394] [-Wx-partial]
    In the use of ‘head’
    (imported from Prelude, but defined in GHC.Internal.List):
    "This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"."
   |
15 |     | head a /= '-' = (read a, readPoint b)
   |       ^^^^

[2 of 2] Linking a.out

ソースコード

diff #
raw source code

import Data.List.Split

main :: IO ()
main = do
    getLine
    a <- map parse . lines <$> getContents
    let (i, p) = (sum $ map fst a, sum $ map snd a)
    putStrLn $ showWithPoint(10^10 * i + p)

parse :: String -> (Integer, Integer)
parse = zipInt . splitWhen (== '.')

zipInt :: [String] -> (Integer, Integer)
zipInt [a, b]
    | head a /= '-' = (read a, readPoint b)
    | otherwise = (read a, -readPoint b)
zipInt [a] = (read a, 0)

readPoint :: String -> Integer
readPoint = read . take 10 . (++ repeat '0')

showWithPoint :: Integer -> String
showWithPoint x
    | x < 0 = '-':showWithPoint (-x)
    | otherwise = (show (x `div` 10 ^ 10)) ++ "." ++ (show10 10 (x `mod` 10^10))

show10 :: Integer -> Integer -> String
show10 0 _ = ""
show10 d x = (show $ x `div` 10^(d-1)) ++ show10 (d - 1) (x `mod` 10^(d-1))
0