結果

問題 No.250 atetubouのzetubou
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-06-07 22:36:24
言語 Haskell
(9.8.2)
結果
MLE  
実行時間 -
コード長 1,146 bytes
コンパイル時間 9,883 ms
コンパイル使用メモリ 183,572 KB
実行使用メモリ 813,056 KB
最終ジャッジ日時 2024-04-17 07:44:48
合計ジャッジ時間 20,532 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Lazy.Char8 as LC
import qualified Data.ByteString.Char8 as SC
import Data.List (genericIndex)
import Data.Maybe (fromJust)

data Status = AC | ZETUBOU deriving (Enum, Show)
type Query a = (a, a, a)

-- Based on https://rosettacode.org/wiki/Evaluate_binomial_coefficients
binom :: Integral a => a -> a -> a
binom n k = flip genericIndex k $ genericIndex binoms n
    where
        next ns = zipWith (+) (0 : ns) $ ns ++ [0]
        binoms = iterate next [1]

querify :: [a] -> Query a
querify [x, y, z] = (x, y, z)
querify _ = error "the length of the list must be three"

judge :: Integral a => Query a -> Status
judge (d, x, t)
    | binom (x + d - 1) x <= t = AC
    | otherwise = ZETUBOU

unsafeReadInteger :: LC.ByteString -> Integer
unsafeReadInteger = fst . fromJust . LC.readInteger

showStatus :: Status -> SC.ByteString
showStatus AC = "AC"
showStatus ZETUBOU = "ZETUBOU"

main :: IO ()
main = do
    _ <- SC.getLine
    SC.putStr . SC.unlines .
        fmap (showStatus . judge . querify . fmap unsafeReadInteger . LC.words) .
            LC.lines =<< LC.getContents
0