結果

問題 No.118 門松列(2)
ユーザー zombietan
提出日時 2016-05-22 16:59:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 67 ms / 5,000 ms
コード長 454 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 17,012 KB
最終ジャッジ日時 2024-10-09 08:11:31
合計ジャッジ時間 2,295 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
ans = N*(N-1)*(N-2)//6

cnt = Counter(A)

def same3(n):
    return n*(n-1)*(n-2)//6 

def same2(n):
    return n*(n-1)//2

def not_kadomatu(n, m):
    if m == 2:
        return same2(m)*(n-m)
    else:
        return same2(m)*(n-m) + same3(m)

for count in cnt.values():
    if count >= 2:
        nk = not_kadomatu(N,count)
        ans = ans - nk

print(ans%1000000007)
0