結果

問題 No.723 2つの数の和
ユーザー sawfish
提出日時 2022-10-24 00:57:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 651 ms
コンパイル使用メモリ 69,608 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 12:44:14
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int N, X;
    cin >> N >> X;

    int a[N];
    for (int i = 0; i < N; i++) cin >> a[i];
    sort(a, a + N);

    LL ans = 0;
    for (int i = 0; i < N; i++) {
        int *p = lower_bound(a, a + N, X - a[i]);
        int *q = upper_bound(a, a + N, X - a[i]);
        if (a[i] + *p == X) ans += q - p;
    }

    cout << ans << endl;
}
0