結果

問題 No.1081 和の和
ユーザー 糸見沙耶香糸見沙耶香
提出日時 2020-07-20 11:53:30
言語 Haskell
(9.8.2)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 11,083 ms
コンパイル使用メモリ 161,712 KB
実行使用メモリ 8,496 KB
最終ジャッジ日時 2023-08-24 23:36:44
合計ジャッジ時間 12,720 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,416 KB
testcase_01 AC 3 ms
7,360 KB
testcase_02 AC 3 ms
7,500 KB
testcase_03 AC 3 ms
7,716 KB
testcase_04 AC 3 ms
8,132 KB
testcase_05 AC 3 ms
7,372 KB
testcase_06 AC 3 ms
7,752 KB
testcase_07 AC 4 ms
8,408 KB
testcase_08 AC 3 ms
8,496 KB
testcase_09 AC 4 ms
8,364 KB
testcase_10 AC 4 ms
8,364 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 #

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