結果

問題 No.420 mod2漸化式
ユーザー alpha_virginisalpha_virginis
提出日時 2016-09-09 23:02:44
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 1,100 bytes
コンパイル時間 7,241 ms
コンパイル使用メモリ 181,676 KB
実行使用メモリ 15,264 KB
最終ジャッジ日時 2024-04-28 02:33:24
合計ジャッジ時間 7,402 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,264 KB
testcase_01 TLE -
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 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Char8 as C
import Data.Char
import Text.Printf

nCr :: Integer -> Integer -> Integer
nCr 0 _ = 1
nCr _ 0 = 1
nCr n r
  | n == 0 = 1
  | r == 0 = 1
  | n == r = 1
  | otherwise = nCr (n - 1) (r' - 1) + nCr (n - 1) r'
  where r' = min r $ n - r
  
solve :: Int -> (Integer, Integer)
solve n
  | n < 32 = (x, y)
  | otherwise = (0, 0)
  where n' = fromIntegral n
        x  = nCr 31 n'
        y  = (2 ^ (31 :: Integer) - 1) * x * n' `div` 31

main :: IO ()
main = do
  ss <- C.getLine
  let (x, ss2) = nextInt ss
  let (a, b) = solve x
  printf "%d %d\n" 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