結果

問題 No.723 2つの数の和
ユーザー ThetaTheta
提出日時 2022-10-18 15:08:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 27,216 KB
最終ジャッジ日時 2023-09-11 08:34:02
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,604 KB
testcase_01 AC 18 ms
8,536 KB
testcase_02 AC 18 ms
8,484 KB
testcase_03 AC 99 ms
22,000 KB
testcase_04 AC 130 ms
23,408 KB
testcase_05 AC 127 ms
23,084 KB
testcase_06 AC 118 ms
22,920 KB
testcase_07 AC 65 ms
16,796 KB
testcase_08 AC 71 ms
17,848 KB
testcase_09 AC 126 ms
23,688 KB
testcase_10 AC 64 ms
17,916 KB
testcase_11 AC 29 ms
10,600 KB
testcase_12 AC 77 ms
18,080 KB
testcase_13 AC 139 ms
23,056 KB
testcase_14 AC 52 ms
15,380 KB
testcase_15 AC 74 ms
18,492 KB
testcase_16 AC 103 ms
21,276 KB
testcase_17 AC 124 ms
22,240 KB
testcase_18 AC 49 ms
10,460 KB
testcase_19 AC 70 ms
20,136 KB
testcase_20 AC 18 ms
8,620 KB
testcase_21 AC 18 ms
8,432 KB
testcase_22 AC 18 ms
8,468 KB
testcase_23 AC 102 ms
27,216 KB
testcase_24 AC 57 ms
16,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    counter_A = defaultdict(int)

    for num in A:
        counter_A[num] += 1
        counter_A[X-num]

    A_unique_list = sorted(set(A))

    patterns = 0
    for num in A_unique_list:
        if num > X - num:
            break

        if num == X - num:
            patterns += counter_A[num] ** 2
            break

        patterns += counter_A[num] * counter_A[X - num] * 2

    print(patterns)


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