結果

問題 No.118 門松列(2)
ユーザー yuppe19 😺
提出日時 2015-04-23 21:51:04
言語 Python2
(2.7.18)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 464 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 12,500 KB
最終ジャッジ日時 2024-10-09 06:58:54
合計ジャッジ時間 2,327 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from collections import Counter
mul = lambda x, y: x*y
def nCr(n, r):
    if r == 0 or n == r:
        return 1
    k = r if r <= n-r else n-r
    return reduce(mul, xrange(n, n-k, -1)) / reduce(mul, xrange(1, k+1))

mod = int(1e9) + 7
n = int(raw_input())
As = map(int, raw_input().split())
res = nCr(n, 3)
for v in filter(lambda e: e>1, Counter(As).values()):
    res -= nCr(v, 2) * (n-v)
    if v >= 3:
        res -= nCr(v, 3)
print res % mod
0