結果

問題 No.118 門松列(2)
ユーザー roaris
提出日時 2019-12-22 12:10:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 475 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 95,616 KB
最終ジャッジ日時 2024-09-14 02:36:54
合計ジャッジ時間 3,537 ms
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 22
権限があれば一括ダウンロードができます

ソースコード

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()))
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