結果

問題 No.118 門松列(2)
ユーザー roarisroaris
提出日時 2019-12-22 12:12:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 469 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 96,344 KB
最終ジャッジ日時 2023-10-12 03:06:59
合計ジャッジ時間 4,752 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
82,736 KB
testcase_01 AC 120 ms
96,336 KB
testcase_02 AC 116 ms
96,344 KB
testcase_03 AC 117 ms
96,192 KB
testcase_04 AC 117 ms
96,180 KB
testcase_05 AC 116 ms
96,136 KB
testcase_06 AC 87 ms
82,268 KB
testcase_07 AC 88 ms
82,204 KB
testcase_08 AC 88 ms
82,184 KB
testcase_09 AC 115 ms
94,476 KB
testcase_10 AC 93 ms
83,300 KB
testcase_11 AC 96 ms
84,524 KB
testcase_12 AC 92 ms
82,660 KB
testcase_13 AC 90 ms
82,972 KB
testcase_14 AC 113 ms
94,496 KB
testcase_15 AC 89 ms
82,720 KB
testcase_16 AC 101 ms
88,168 KB
testcase_17 AC 89 ms
82,776 KB
testcase_18 AC 96 ms
84,636 KB
testcase_19 AC 100 ms
87,024 KB
testcase_20 AC 101 ms
88,080 KB
testcase_21 AC 108 ms
92,812 KB
testcase_22 AC 93 ms
83,624 KB
testcase_23 AC 107 ms
91,352 KB
testcase_24 AC 96 ms
85,012 KB
testcase_25 AC 99 ms
87,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def inv(x):
    return pow(x, MOD-2, MOD)

def C(n, r):
    if r>n:
        return 0
    return fact[n]*inv(fact[r])*inv(fact[n-r])

N = int(input())
A = list(map(int, input().split()))
A.sort()
MOD = 10**9+7

A.append(-1)
fact = [1]

for i in range(1, 10**5+100):
    fact.append(fact[-1]*i%MOD)
    
ans = C(N, 3)
c = 1

for i in range(N):
    if A[i]!=A[i+1]:
        ans -= C(c, 3)
        ans -= C(c, 2)*(N-c)
        c = 1
    else:
        c += 1

print(ans%MOD)
0