結果

問題 No.723 2つの数の和
ユーザー MIKI TakushiMIKI Takushi
提出日時 2018-12-31 00:06:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 916 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 20,924 KB
最終ジャッジ日時 2024-04-17 16:56:01
合計ジャッジ時間 12,433 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,752 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 28 ms
10,624 KB
testcase_03 AC 608 ms
17,236 KB
testcase_04 AC 883 ms
19,920 KB
testcase_05 AC 793 ms
19,028 KB
testcase_06 AC 786 ms
19,044 KB
testcase_07 AC 326 ms
14,392 KB
testcase_08 AC 379 ms
15,388 KB
testcase_09 AC 800 ms
20,288 KB
testcase_10 AC 343 ms
14,332 KB
testcase_11 AC 82 ms
11,648 KB
testcase_12 AC 416 ms
15,816 KB
testcase_13 AC 882 ms
20,740 KB
testcase_14 AC 212 ms
13,184 KB
testcase_15 AC 379 ms
14,488 KB
testcase_16 AC 558 ms
16,744 KB
testcase_17 AC 744 ms
18,836 KB
testcase_18 AC 793 ms
12,740 KB
testcase_19 AC 830 ms
20,924 KB
testcase_20 AC 28 ms
10,752 KB
testcase_21 AC 29 ms
10,624 KB
testcase_22 AC 29 ms
10,752 KB
testcase_23 AC 916 ms
20,592 KB
testcase_24 AC 251 ms
13,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
n,x = map(int, input().split())
al = [int(x) for x in input().split()]
al.sort()


def lower_bound(al, key):
    def isOk(a):
        return a>=key
    ng = -1
    ok = len(al)
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid
    return ok

def upper_bound(al, key):
    def isOk(a):
        return a>key
    ng = -1
    ok = len(al)
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if isOk(al[mid]):
            ok = mid
        else:
            ng = mid
    return ok

cnt = 0
for a in al:
    l = lower_bound(al, x-a)
    u = upper_bound(al, x-a)
    if u>l>=0:
        cnt += u-l

print(cnt)
0