結果

問題 No.118 門松列(2)
ユーザー roarisroaris
提出日時 2019-12-22 12:13:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 484 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 96,260 KB
最終ジャッジ日時 2023-10-12 03:07:11
合計ジャッジ時間 4,211 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
82,592 KB
testcase_01 AC 113 ms
96,156 KB
testcase_02 AC 118 ms
96,036 KB
testcase_03 AC 111 ms
96,260 KB
testcase_04 AC 111 ms
95,924 KB
testcase_05 AC 113 ms
95,980 KB
testcase_06 AC 83 ms
81,996 KB
testcase_07 AC 82 ms
82,092 KB
testcase_08 AC 82 ms
82,200 KB
testcase_09 AC 108 ms
94,344 KB
testcase_10 AC 89 ms
83,132 KB
testcase_11 AC 93 ms
84,328 KB
testcase_12 AC 88 ms
82,516 KB
testcase_13 AC 86 ms
82,612 KB
testcase_14 AC 110 ms
94,392 KB
testcase_15 AC 86 ms
82,512 KB
testcase_16 AC 98 ms
88,004 KB
testcase_17 AC 87 ms
82,552 KB
testcase_18 AC 91 ms
84,256 KB
testcase_19 AC 96 ms
87,088 KB
testcase_20 AC 99 ms
87,636 KB
testcase_21 AC 106 ms
92,548 KB
testcase_22 AC 89 ms
83,420 KB
testcase_23 AC 101 ms
91,160 KB
testcase_24 AC 93 ms
85,032 KB
testcase_25 AC 95 ms
86,784 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)
        ans %= MOD
        c = 1
    else:
        c += 1

print(ans)
0