結果

問題 No.118 門松列(2)
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-04-23 21:51:04
言語 Python2
(2.7.18)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 464 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 12,372 KB
最終ジャッジ日時 2024-04-17 12:58:00
合計ジャッジ時間 2,117 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
6,784 KB
testcase_01 AC 77 ms
12,372 KB
testcase_02 AC 74 ms
12,316 KB
testcase_03 AC 77 ms
12,284 KB
testcase_04 AC 79 ms
12,352 KB
testcase_05 AC 79 ms
12,344 KB
testcase_06 AC 13 ms
6,656 KB
testcase_07 AC 12 ms
6,656 KB
testcase_08 AC 13 ms
6,656 KB
testcase_09 AC 74 ms
12,148 KB
testcase_10 AC 25 ms
7,680 KB
testcase_11 AC 29 ms
8,064 KB
testcase_12 AC 22 ms
7,424 KB
testcase_13 AC 18 ms
7,168 KB
testcase_14 AC 74 ms
11,808 KB
testcase_15 AC 14 ms
6,784 KB
testcase_16 AC 45 ms
9,728 KB
testcase_17 AC 18 ms
7,168 KB
testcase_18 AC 30 ms
8,192 KB
testcase_19 AC 41 ms
9,216 KB
testcase_20 AC 43 ms
9,344 KB
testcase_21 AC 62 ms
11,136 KB
testcase_22 AC 26 ms
7,808 KB
testcase_23 AC 57 ms
10,496 KB
testcase_24 AC 32 ms
8,448 KB
testcase_25 AC 40 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

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