結果
| 問題 |
No.420 mod2漸化式
|
| コンテスト | |
| ユーザー |
alpha_virginis
|
| 提出日時 | 2016-09-09 23:02:44 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,100 bytes |
| コンパイル時間 | 11,057 ms |
| コンパイル使用メモリ | 181,796 KB |
| 実行使用メモリ | 18,432 KB |
| 最終ジャッジ日時 | 2024-11-16 10:52:59 |
| 合計ジャッジ時間 | 43,080 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 TLE * 15 |
コンパイルメッセージ
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
ソースコード
{-# 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
alpha_virginis