結果

問題 No.118 門松列(2)
ユーザー aimyaimy
提出日時 2017-04-21 16:58:55
言語 Haskell
(9.8.2)
結果
AC  
実行時間 363 ms / 5,000 ms
コード長 430 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 160,792 KB
実行使用メモリ 43,168 KB
最終ジャッジ日時 2023-09-27 10:57:58
合計ジャッジ時間 6,506 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
13,496 KB
testcase_01 AC 363 ms
42,844 KB
testcase_02 AC 332 ms
42,400 KB
testcase_03 AC 342 ms
41,976 KB
testcase_04 AC 352 ms
41,716 KB
testcase_05 AC 363 ms
43,168 KB
testcase_06 AC 2 ms
7,248 KB
testcase_07 AC 2 ms
7,244 KB
testcase_08 AC 2 ms
7,380 KB
testcase_09 AC 332 ms
40,136 KB
testcase_10 AC 52 ms
17,224 KB
testcase_11 AC 72 ms
18,728 KB
testcase_12 AC 42 ms
16,956 KB
testcase_13 AC 32 ms
13,600 KB
testcase_14 AC 302 ms
40,980 KB
testcase_15 AC 12 ms
11,696 KB
testcase_16 AC 163 ms
24,852 KB
testcase_17 AC 22 ms
14,284 KB
testcase_18 AC 72 ms
18,236 KB
testcase_19 AC 132 ms
24,324 KB
testcase_20 AC 143 ms
24,148 KB
testcase_21 AC 242 ms
31,980 KB
testcase_22 AC 62 ms
17,536 KB
testcase_23 AC 222 ms
32,020 KB
testcase_24 AC 82 ms
18,924 KB
testcase_25 AC 112 ms
24,172 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 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