結果

問題 No.1470 Mex Sum
ユーザー GrayCoderGrayCoder
提出日時 2021-04-09 22:46:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 522 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 16,536 KB
最終ジャッジ日時 2023-09-07 12:23:07
合計ジャッジ時間 6,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,528 KB
testcase_01 AC 19 ms
8,488 KB
testcase_02 AC 25 ms
9,220 KB
testcase_03 AC 26 ms
9,412 KB
testcase_04 AC 26 ms
9,248 KB
testcase_05 AC 26 ms
9,196 KB
testcase_06 AC 26 ms
9,416 KB
testcase_07 AC 26 ms
9,192 KB
testcase_08 AC 26 ms
9,272 KB
testcase_09 AC 26 ms
9,284 KB
testcase_10 AC 26 ms
9,260 KB
testcase_11 AC 26 ms
9,340 KB
testcase_12 AC 98 ms
16,196 KB
testcase_13 AC 97 ms
15,844 KB
testcase_14 AC 96 ms
15,912 KB
testcase_15 AC 99 ms
15,880 KB
testcase_16 AC 96 ms
15,856 KB
testcase_17 AC 96 ms
15,872 KB
testcase_18 AC 95 ms
15,852 KB
testcase_19 AC 95 ms
15,812 KB
testcase_20 AC 96 ms
15,984 KB
testcase_21 AC 100 ms
16,148 KB
testcase_22 AC 100 ms
15,968 KB
testcase_23 AC 100 ms
16,536 KB
testcase_24 AC 102 ms
15,968 KB
testcase_25 AC 100 ms
15,940 KB
testcase_26 AC 100 ms
15,960 KB
testcase_27 AC 98 ms
15,944 KB
testcase_28 AC 100 ms
15,952 KB
testcase_29 AC 100 ms
15,956 KB
testcase_30 AC 100 ms
15,944 KB
testcase_31 AC 101 ms
16,024 KB
testcase_32 AC 99 ms
15,960 KB
testcase_33 AC 100 ms
16,084 KB
testcase_34 AC 98 ms
16,056 KB
testcase_35 AC 99 ms
16,088 KB
testcase_36 AC 99 ms
16,268 KB
testcase_37 AC 62 ms
11,112 KB
testcase_38 AC 62 ms
11,152 KB
testcase_39 AC 60 ms
11,156 KB
testcase_40 AC 63 ms
11,064 KB
testcase_41 AC 62 ms
11,132 KB
testcase_42 AC 61 ms
11,176 KB
testcase_43 AC 61 ms
11,160 KB
testcase_44 AC 61 ms
11,232 KB
testcase_45 AC 61 ms
11,224 KB
testcase_46 AC 61 ms
11,160 KB
testcase_47 AC 62 ms
11,224 KB
testcase_48 AC 62 ms
11,112 KB
testcase_49 AC 61 ms
11,108 KB
testcase_50 AC 62 ms
11,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = map(int, input().split())

    nums = sorted(Counter(A).items())
    one, two = 0, 0
    if nums[0][0] == 1:
        one = nums[0][1]
    if len(nums) > 1 and nums[1][0] == 2:
        two = nums[1][1]
    other = N - one - two

    ans = (one - 1) * one // 2 * 2
    ans += one * two * 3
    ans += one * other * 2
    n = N - one
    ans += (n - 1) * n // 2
    print(ans)


main()
0