結果

問題 No.118 門松列(2)
ユーザー aimy
提出日時 2017-04-21 16:58:55
言語 Haskell
(9.10.1)
結果
AC  
実行時間 388 ms / 5,000 ms
コード長 430 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 173,540 KB
実行使用メモリ 39,684 KB
最終ジャッジ日時 2024-07-20 05:07:39
合計ジャッジ時間 7,099 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Data.List

q = 10^9+7

comb n r = iterate (scanl1 (+)) [1,1..] !! (n'-r') !! r'
 where [n',r'] = map fromIntegral [n,r]

main = getContents >>= print . kadomatsu . map read . words

kadomatsu :: [Integer] -> Integer
kadomatsu (n:as) = mod (comb n 3 - dup) q
 where
  dup = sum $ map comb' $ filter (>1) $ map (fromIntegral . length) $ group $ sort as
  comb' m
   | m==2 = n - m
   | otherwise = comb m 2 * (n-m) + comb m 3
0