結果

問題 No.1470 Mex Sum
ユーザー LyricalMaestro
提出日時 2025-09-20 17:51:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 82,236 KB
実行使用メモリ 103,084 KB
最終ジャッジ日時 2025-09-20 17:52:01
合計ジャッジ時間 6,823 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2944


def main():
    N = int(input())
    A = list(map(int, input().split()))

    a_counts = [0] * 4
    for a in A:
        x = min(a, 3)
        a_counts[x] += 1

    answer = 0
    # 回答が一
    n = a_counts[2] + a_counts[3]
    answer += (n * (n - 1)) // 2

    # 回答が2
    answer += 2 * a_counts[1] * a_counts[3]
    n = a_counts[1]
    answer += 2 * ((n * (n - 1)) //2)

    # 回答3
    answer += 3 * a_counts[1] * a_counts[2]
  

    print(answer)


if __name__ == "__main__":
    main()
0