結果

問題 No.723 2つの数の和
ユーザー LaylaLayla
提出日時 2018-09-29 10:13:45
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 928 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 66,408 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-20 12:46:27
合計ジャッジ時間 4,607 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

typedef long long ll;
using namespace std;

template<typename T>
int binary_search_find_index(std::vector<T> v, int data) {
    auto it = std::lower_bound(v.begin(), v.end(), data);
    if (it == v.end() || *it != data) {
        return -1;
    } else {
        std::size_t index = std::distance(v.begin(), it);
        return index;
    }
}

int main(void) {
    ll x, n;
    int idx;
    int count = 0;
    vector<ll> a;
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        ll temp;
        cin >> temp;
        a.push_back(temp);
    }

    sort(a.begin(), a.end());

    for (int j = 0; j < n; ++j) {
        if ((idx = binary_search_find_index(a, x - a[j])) >= 0) {
            for (int i = idx; i < n; ++i) {
                if (a[i] == x - a[j]) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}
0