結果

問題 No.723 2つの数の和
ユーザー tokizo
提出日時 2019-03-09 10:35:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 1,817 ms
コンパイル使用メモリ 179,344 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-06-23 15:11:32
合計ジャッジ時間 3,203 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, x;
    cin >> n >> x;
    vector<int> A(n);
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        mp[A[i]]++;
    }

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        int r = x - A[i];
        if(r < 0) continue;
        int idx = lower_bound(A.begin(), A.end(), r) - A.begin();
        if(idx == n) continue;
        if(A[idx] == r) ans += mp[r];
    }

    cout << ans << endl;

    return 0;
}
0