結果

問題 No.419 直角三角形
ユーザー alpha_virginisalpha_virginis
提出日時 2016-09-09 22:45:17
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 938 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 158,116 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2023-08-10 08:56:19
合計ジャッジ時間 1,972 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,876 KB
testcase_01 AC 2 ms
7,840 KB
testcase_02 AC 3 ms
7,884 KB
testcase_03 AC 2 ms
7,920 KB
testcase_04 AC 2 ms
7,972 KB
testcase_05 AC 3 ms
7,852 KB
testcase_06 AC 2 ms
7,852 KB
testcase_07 AC 3 ms
7,956 KB
testcase_08 AC 2 ms
7,820 KB
testcase_09 AC 3 ms
7,924 KB
testcase_10 AC 3 ms
7,940 KB
testcase_11 AC 3 ms
7,880 KB
testcase_12 AC 2 ms
7,828 KB
testcase_13 AC 3 ms
7,964 KB
testcase_14 AC 2 ms
7,932 KB
testcase_15 AC 3 ms
7,924 KB
testcase_16 AC 3 ms
7,856 KB
testcase_17 AC 2 ms
7,964 KB
testcase_18 AC 2 ms
7,920 KB
testcase_19 AC 2 ms
7,832 KB
testcase_20 AC 3 ms
7,880 KB
testcase_21 AC 3 ms
7,920 KB
testcase_22 AC 2 ms
7,952 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 #

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as C
import Data.Char
import Text.Printf

solve :: Int -> Int -> Double
solve a b
  | a == b    = sqrt $ x ** 2 + y ** 2
  | otherwise = sqrt $ x ** 2 - y ** 2
  where a2 = realToFrac a
        b2 = realToFrac b
        x  = max a2 b2
        y  = min a2 b2

main :: IO ()
main = do
  ss <- C.getLine
  let (a, ss2) = nextInt ss
  let (b, ss3) = nextInt ss2
  printf "%.20f\n" $ solve a b

nextInt :: C.ByteString -> (Int, C.ByteString)
nextInt ss
  | isDigit x || x == '-' = nextInt2 0 ss
  | otherwise             = nextInt $ C.tail ss
  where x = C.head ss
  
nextInt2 :: Int -> C.ByteString -> (Int, C.ByteString)
nextInt2 n ss
  | C.null ss = (n, ss)
  | y == '-'  = (-z,zs)
  | isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys
  | otherwise = (n, ys)
  where y  = C.head ss
        ys = C.tail ss
        (z,zs) = nextInt2 0 ys
                           
0