結果
| 問題 | 
                            No.1470 Mex Sum
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2022-10-12 19:33:35 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 87 ms / 2,000 ms | 
| コード長 | 629 bytes | 
| コンパイル時間 | 192 ms | 
| コンパイル使用メモリ | 12,544 KB | 
| 実行使用メモリ | 19,152 KB | 
| 最終ジャッジ日時 | 2024-06-26 11:27:52 | 
| 合計ジャッジ時間 | 5,383 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 49 | 
ソースコード
def main():
    N = int(input())
    A = list(map(int, input().split()))
    num_1_in_A = A.count(1)
    num_2_in_A = A.count(2)
    num_other_in_A = N - num_1_in_A - num_2_in_A
    sum_mex = 0
    if num_1_in_A > 1:
        sum_mex += num_1_in_A * (num_1_in_A - 1)
    sum_mex += 3 * num_1_in_A * num_2_in_A
    sum_mex += 2 * num_1_in_A * num_other_in_A
    if num_2_in_A > 1:
        sum_mex += num_2_in_A * (num_2_in_A - 1) // 2
    sum_mex += num_2_in_A * num_other_in_A
    if num_other_in_A > 1:
        sum_mex += num_other_in_A * (num_other_in_A - 1) // 2
    print(sum_mex)
if __name__ == "__main__":
    main()