結果

問題 No.420 mod2漸化式
ユーザー alpha_virginisalpha_virginis
提出日時 2016-09-09 23:07:01
言語 Haskell
(9.6.2)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,001 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 164,064 KB
実行使用メモリ 7,752 KB
最終ジャッジ日時 2023-08-25 23:20:22
合計ジャッジ時間 3,191 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,364 KB
testcase_01 AC 3 ms
7,748 KB
testcase_02 AC 2 ms
7,380 KB
testcase_03 AC 3 ms
7,360 KB
testcase_04 AC 2 ms
7,360 KB
testcase_05 AC 2 ms
7,440 KB
testcase_06 AC 2 ms
7,392 KB
testcase_07 AC 3 ms
7,392 KB
testcase_08 AC 3 ms
7,396 KB
testcase_09 AC 2 ms
7,424 KB
testcase_10 AC 3 ms
7,292 KB
testcase_11 AC 2 ms
7,440 KB
testcase_12 AC 2 ms
7,400 KB
testcase_13 AC 3 ms
7,368 KB
testcase_14 AC 3 ms
7,392 KB
testcase_15 AC 3 ms
7,444 KB
testcase_16 AC 2 ms
7,656 KB
testcase_17 AC 3 ms
7,652 KB
testcase_18 AC 3 ms
7,624 KB
testcase_19 AC 3 ms
7,540 KB
testcase_20 AC 3 ms
7,636 KB
testcase_21 AC 2 ms
7,524 KB
testcase_22 AC 3 ms
7,752 KB
testcase_23 AC 3 ms
7,676 KB
testcase_24 AC 2 ms
7,740 KB
testcase_25 AC 3 ms
7,576 KB
testcase_26 AC 2 ms
7,540 KB
testcase_27 AC 3 ms
7,724 KB
testcase_28 AC 2 ms
7,732 KB
testcase_29 AC 3 ms
7,580 KB
testcase_30 AC 3 ms
7,544 KB
testcase_31 AC 3 ms
7,572 KB
testcase_32 AC 2 ms
7,556 KB
testcase_33 AC 3 ms
7,140 KB
testcase_34 AC 3 ms
7,300 KB
testcase_35 AC 2 ms
7,296 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

nCr :: Integer -> Integer -> Integer
nCr n r = foldl (*) 1 [n-r+1..n] `div` foldl (*) 1 [1..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