結果

問題 No.338 アンケート機能
ユーザー kuwakuwa
提出日時 2016-01-29 22:42:23
言語 Haskell
(9.8.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,319 bytes
コンパイル時間 9,297 ms
コンパイル使用メモリ 162,632 KB
実行使用メモリ 10,016 KB
最終ジャッジ日時 2023-08-07 21:24:16
合計ジャッジ時間 10,763 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,096 KB
testcase_01 AC 3 ms
7,356 KB
testcase_02 AC 2 ms
7,168 KB
testcase_03 AC 2 ms
7,024 KB
testcase_04 AC 2 ms
7,024 KB
testcase_05 AC 5 ms
9,920 KB
testcase_06 AC 2 ms
7,052 KB
testcase_07 AC 5 ms
9,952 KB
testcase_08 AC 2 ms
7,148 KB
testcase_09 AC 5 ms
9,924 KB
testcase_10 AC 3 ms
7,068 KB
testcase_11 AC 3 ms
7,056 KB
testcase_12 AC 2 ms
7,020 KB
testcase_13 AC 2 ms
7,036 KB
testcase_14 AC 2 ms
7,104 KB
testcase_15 AC 3 ms
7,032 KB
testcase_16 AC 2 ms
7,100 KB
testcase_17 AC 2 ms
7,032 KB
testcase_18 AC 2 ms
7,056 KB
testcase_19 AC 3 ms
7,204 KB
testcase_20 AC 5 ms
9,940 KB
testcase_21 AC 5 ms
9,832 KB
testcase_22 AC 5 ms
9,904 KB
testcase_23 AC 3 ms
7,252 KB
testcase_24 AC 3 ms
7,164 KB
testcase_25 AC 6 ms
9,852 KB
testcase_26 AC 5 ms
9,908 KB
testcase_27 AC 5 ms
10,016 KB
testcase_28 AC 2 ms
7,220 KB
testcase_29 AC 3 ms
7,064 KB
testcase_30 AC 2 ms
6,988 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 #

module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

main :: IO ()
main = do
    [a, b] <- readInts
    print $ solve a b

solve :: Int -> Int -> Int
solve a b = rec 1
    where rec m 
            | null cand = rec (m+1) 
            | otherwise = m
              where cand = filter (== (a,b)) $ map percentize $ take (m+1) $ zip [0..] [m,m-1..]
          percentize (a,b) = (roundUpOn5 $ 100 * fromIntegral a / fromIntegral (a + b),
                            roundUpOn5 $ 100 * fromIntegral b / fromIntegral (a + b))

roundUpOn5 :: (RealFrac a, Integral b) => a -> b
roundUpOn5 x
  | n <= -0.5 = m - 1
    | n >= 0.5 = m + 1
      | otherwise = m
        where (m, n) = properFraction x

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Doub le Formatting -}

doubleFormat :: Double -> String
doubleFormat = Text.Printf.printf "%.12f"
0