結果

問題 No.723 2つの数の和
ユーザー ryusuke
提出日時 2022-01-27 01:40:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 121,772 KB
最終ジャッジ日時 2024-12-24 00:11:48
合計ジャッジ時間 3,516 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

n, x = map(int, input().split())
a = list(map(int, input().split()))

d_1 = defaultdict(int)
d_2 = defaultdict(int)
for i in a:
    d_1[i] += 1
    d_2[i] += 1

ans = 0
'''
k + t = x
kがv個、tがd_2[t]個 -> v * d_2[t] (k != t)
kがv個、tがd_2[t]個 -> v ** 2 (k == t)
'''
for k, v in d_1.items():
    t = x - k
    if t < 0: continue
    ans += v * d_2[t]

print(ans)
0