結果

問題 No.1470 Mex Sum
ユーザー ThetaTheta
提出日時 2022-10-12 19:33:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 15,776 KB
最終ジャッジ日時 2023-09-08 18:37:32
合計ジャッジ時間 5,160 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,912 KB
testcase_01 AC 16 ms
7,960 KB
testcase_02 AC 20 ms
8,900 KB
testcase_03 AC 22 ms
8,780 KB
testcase_04 AC 21 ms
8,988 KB
testcase_05 AC 20 ms
8,764 KB
testcase_06 AC 20 ms
8,932 KB
testcase_07 AC 20 ms
8,784 KB
testcase_08 AC 20 ms
8,968 KB
testcase_09 AC 20 ms
8,888 KB
testcase_10 AC 21 ms
8,852 KB
testcase_11 AC 20 ms
8,976 KB
testcase_12 AC 62 ms
15,600 KB
testcase_13 AC 61 ms
15,440 KB
testcase_14 AC 61 ms
15,500 KB
testcase_15 AC 62 ms
15,460 KB
testcase_16 AC 61 ms
15,528 KB
testcase_17 AC 60 ms
15,324 KB
testcase_18 AC 60 ms
15,436 KB
testcase_19 AC 61 ms
15,336 KB
testcase_20 AC 60 ms
15,468 KB
testcase_21 AC 63 ms
15,488 KB
testcase_22 AC 63 ms
15,748 KB
testcase_23 AC 63 ms
15,776 KB
testcase_24 AC 63 ms
15,512 KB
testcase_25 AC 63 ms
15,688 KB
testcase_26 AC 63 ms
15,704 KB
testcase_27 AC 62 ms
15,628 KB
testcase_28 AC 62 ms
15,660 KB
testcase_29 AC 62 ms
15,568 KB
testcase_30 AC 62 ms
15,684 KB
testcase_31 AC 63 ms
15,588 KB
testcase_32 AC 62 ms
15,628 KB
testcase_33 AC 62 ms
15,628 KB
testcase_34 AC 63 ms
15,660 KB
testcase_35 AC 62 ms
15,556 KB
testcase_36 AC 62 ms
15,612 KB
testcase_37 AC 51 ms
11,332 KB
testcase_38 AC 51 ms
11,380 KB
testcase_39 AC 53 ms
11,208 KB
testcase_40 AC 53 ms
11,284 KB
testcase_41 AC 53 ms
11,328 KB
testcase_42 AC 53 ms
11,432 KB
testcase_43 AC 53 ms
11,228 KB
testcase_44 AC 53 ms
11,396 KB
testcase_45 AC 53 ms
11,228 KB
testcase_46 AC 53 ms
11,392 KB
testcase_47 AC 53 ms
11,344 KB
testcase_48 AC 52 ms
11,428 KB
testcase_49 AC 54 ms
11,396 KB
testcase_50 AC 53 ms
11,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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