結果

問題 No.1081 和の和
ユーザー 糸見沙耶香
提出日時 2020-07-20 11:53:30
言語 Haskell
(9.10.1)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 9,886 ms
コンパイル使用メモリ 180,172 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 10:11:21
合計ジャッジ時間 10,625 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

import qualified Data.List as L
import qualified Data.Maybe as Maybe 
import qualified Data.ByteString.Char8 as BSC8 

readIntegers :: IO [Integer]
readIntegers = map (fst . Maybe.fromJust . BSC8.readInteger) . BSC8.words <$> BSC8.getLine

factorial n = product [n, n-1 .. 1]
nCr n r = n' `div` r'
    where
    -- unroll just what you need and nothing more
    n' = product [n, n-1 .. n-r+1]
    r' = factorial r
main :: IO ()
main = do
  n <- readLn :: IO Integer
  xs <- readIntegers
  print $ flip mod 1000000007 $ snd $ L.foldl1' (\acc x -> (fst x, (snd acc) + (snd x * nCr (n - 1) (fst x)))) $ zip [0 ..] xs
0