結果

問題 No.118 門松列(2)
コンテスト
ユーザー yuppe19 😺
提出日時 2015-04-23 21:51:04
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 106 ms / 5,000 ms
コード長 464 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 180 ms
コンパイル使用メモリ 77,556 KB
最終ジャッジ日時 2025-12-03 14:44:25
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/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