結果

問題 No.723 2つの数の和
ユーザー dsaito11
提出日時 2019-07-27 11:55:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 88,548 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 10:49:41
合計ジャッジ時間 2,573 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define INF 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main() {
    int n, x;
    cin >> n >> x;

    vector<int> a(n);

    int i;
    for(i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    long long int ans = 0;
    for(i = 0; i < n; i++){
        ans += upper_bound(a.begin(), a.end(), x-a[i]) - lower_bound(a.begin(), a.end(), x-a[i]);
    }

    cout << ans << endl;
}

0