結果

問題 No.723 2つの数の和
ユーザー PachicobuePachicobue
提出日時 2018-08-03 22:47:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 198,936 KB
最終ジャッジ日時 2025-01-06 12:13:37
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

//=================================
// Created on: 2018/08/03 22:45:10
//=================================
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};
int main()
{
    int N, X;
    std::cin >> N >> X;
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) { std::cin >> A[i]; }
    std::sort(A.begin(), A.end());
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        const int D = X - A[i];
        ans += std::upper_bound(A.begin(), A.end(), D) - std::lower_bound(A.begin(), A.end(), D);
    }
    std::cout << ans << std::endl;
    return 0;
}
0