結果
| 問題 | No.117 組み合わせの数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-27 00:22:21 |
| 言語 | Haskell (9.10.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,404 bytes |
| 記録 | |
| コンパイル時間 | 4,335 ms |
| コンパイル使用メモリ | 201,216 KB |
| 実行使用メモリ | 627,856 KB |
| 最終ジャッジ日時 | 2024-10-12 04:23:52 |
| 合計ジャッジ時間 | 9,950 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | MLE * 1 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:41:10: warning: [GHC-63394] [-Wx-partial]
In the use of ‘tail’
(imported from Data.List, but defined in GHC.List):
"This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
|
41 | s' = tail . init $ s
| ^^^^
Main.hs:43:40: warning: [GHC-63394] [-Wx-partial]
In the use of ‘tail’
(imported from Data.List, but defined in GHC.List):
"This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
|
43 | (n,k) = (\(a,b) -> (read a, read $ tail b)) $ splitAt i s'
| ^^^^
[2 of 2] Linking a.out
ソースコード
import Control.Monad
import qualified Data.Vector as V
import Data.List
import Data.Int
{-- n^p mod m --}
powerMod :: Integral a => a -> a -> a -> a
powerMod n 0 m = 1
powerMod n 1 m = n `mod` m
powerMod n p m = (k * k * (if mod p 2 == 0 then 1 else n)) `mod` m
where
k = powerMod n (div p 2) m
modinv n p = powerMod n (p-2) p
factorials n m = scanl (\a b -> (a*b) `mod` m) 1 [1..n]
divisor = 10^9+7
numElem = 10^6*2
factorials_ = V.fromList $ factorials numElem divisor
invfactorials_ = V.fromList $
reverse $ scanl (\a b -> (a*(b+1))`mod`divisor) (modinv (factorials_ V.! (fromIntegral numElem)) divisor) (reverse [0..numElem-1])
combinationModP_2 n k
| n < k || n < 0 || k < 0 = 0
| otherwise = (factorials_ V.! n * invfactorials_ V.! k * invfactorials_ V.! (n-k)) `mod` divisor
permutationMod_2 n k
| n < k || n < 0 || k < 0 = 0
| otherwise = (factorials_ V.! n * invfactorials_ V.! (n-k)) `mod` divisor
hcombinationModP_2 n k
| n < 0 || k < 0 = 0
| otherwise = combinationModP_2 (n+k-1) k
parse (c:s) = case c of
'C' -> combinationModP_2 n k
'P' -> permutationMod_2 n k
'H' -> hcombinationModP_2 n k
where
s' = tail . init $ s
Just i = elemIndex ',' s'
(n,k) = (\(a,b) -> (read a, read $ tail b)) $ splitAt i s'
main = do
n <- readLn :: IO Int
replicateM_ n $ do
s <- getLine
print $ parse s