結果

問題 No.1470 Mex Sum
ユーザー moharan627
提出日時 2021-04-09 21:42:24
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,229 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 18,932 KB
最終ジャッジ日時 2024-06-25 04:47:18
合計ジャッジ時間 17,294 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LC(): return list(input())
def IC(): return [int(c) for c in input()]
def MI(): return map(int, sys.stdin.readline().split())
INF = float('inf')
MOD = 10**9 + 7
def solve():
    N = II()
    A = LI()
    One = 0
    Two = 0
    Other = 0
    for a in A:
        if(a==1):
            One+=1
        elif(a==2):
            Two+=1
        else:
            Other+=1
    import math
    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    Thrid = One*Two
    if(One>0):
        Second = combinations_count(One, 2) + One*Other
    else:
        Second = 0
    First = (N*(N-1))//2 - Thrid -Second
    print(3*Thrid+2*Second + First)
    return
solve()
0