結果

問題 No.723 2つの数の和
ユーザー siro53siro53
提出日時 2018-12-23 03:38:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 560 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 11,896 KB
実行使用メモリ 23,880 KB
最終ジャッジ日時 2023-10-26 02:24:03
合計ジャッジ時間 3,397 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,092 KB
testcase_01 AC 29 ms
10,092 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 135 ms
11,888 KB
testcase_19 AC 156 ms
21,608 KB
testcase_20 AC 30 ms
10,092 KB
testcase_21 RE -
testcase_22 AC 29 ms
10,092 KB
testcase_23 AC 349 ms
23,880 KB
testcase_24 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def bs(array, aim):
    left = 0
    right = len(array) - 1

    while left <= right:
        pivot = (left + right) // 2
        if array[pivot] == aim:
            return 1
        elif array[pivot] > aim:
            right = pivot - 1
        else:
            left = pivot + 1
    return 0

N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

B = {}
for a in A:
    if a in B:
        B[a] += 1
    else:
        B[a] = 1

ans = 0
for a in range(N):
    ans += bs(A, X - A[a]) * B[X - A[a]]
print(ans)
0