結果

問題 No.723 2つの数の和
ユーザー Esire
提出日時 2018-08-07 00:50:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,187 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 73,676 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 18:19:47
合計ジャッジ時間 1,831 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
//最大公約数: gcd()
//最小公倍数: lcm()

#define ll long long int

using namespace std;

template <typename T>
void in(T &t){ //標準入力
    cin >> t;
    return;
}

template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::greater<int>());
    return;
}

template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::less<int>());
    return;
}

int main(){
    ll n, x, temp, count = 0;
    vector<ll> v(100001, 0);

    cin >> n >> x;
    for(ll i = 0; i < n; i++){
        cin >> temp;
        v[temp]++;
    }

    for(ll i = 0; i <= 100000; i++){
        if(x - i > 100000) continue;
        if(i >= x - i){
            if(i == x - i && v[i] != 0) count += (ll)(v[i] * v[i]);
            break;
        }
        if(v[i] != 0 && v[x - i] != 0){
            count += (ll)(v[i] * v[x - i] * 2);
        }
    }

    cout << count << endl;

    return 0;
}
0