結果

問題 No.723 2つの数の和
ユーザー siro53siro53
提出日時 2018-12-23 15:09:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 11,968 KB
実行使用メモリ 24,708 KB
最終ジャッジ日時 2023-10-26 02:30:09
合計ジャッジ時間 5,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,088 KB
testcase_01 AC 27 ms
10,088 KB
testcase_02 AC 27 ms
10,088 KB
testcase_03 AC 278 ms
23,264 KB
testcase_04 AC 373 ms
24,632 KB
testcase_05 AC 347 ms
23,856 KB
testcase_06 AC 346 ms
23,244 KB
testcase_07 AC 164 ms
17,204 KB
testcase_08 AC 183 ms
18,196 KB
testcase_09 AC 368 ms
24,564 KB
testcase_10 AC 159 ms
17,196 KB
testcase_11 AC 51 ms
11,860 KB
testcase_12 AC 204 ms
18,476 KB
testcase_13 AC 404 ms
24,380 KB
testcase_14 AC 107 ms
14,412 KB
testcase_15 AC 179 ms
17,384 KB
testcase_16 AC 258 ms
22,852 KB
testcase_17 AC 341 ms
24,708 KB
testcase_18 AC 136 ms
11,884 KB
testcase_19 AC 159 ms
21,608 KB
testcase_20 AC 28 ms
10,088 KB
testcase_21 AC 27 ms
10,088 KB
testcase_22 AC 27 ms
10,088 KB
testcase_23 AC 350 ms
23,876 KB
testcase_24 AC 131 ms
16,972 KB
権限があれば一括ダウンロードができます

ソースコード

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

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

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