結果

問題 No.723 2つの数の和
ユーザー tokizotokizo
提出日時 2019-03-09 10:41:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 175,180 KB
実行使用メモリ 11,252 KB
最終ジャッジ日時 2023-09-05 19:48:29
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 49 ms
8,936 KB
testcase_04 AC 65 ms
9,668 KB
testcase_05 AC 60 ms
9,968 KB
testcase_06 AC 61 ms
9,592 KB
testcase_07 AC 28 ms
7,184 KB
testcase_08 AC 32 ms
7,444 KB
testcase_09 AC 69 ms
10,552 KB
testcase_10 AC 26 ms
6,756 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 38 ms
8,256 KB
testcase_13 AC 72 ms
11,252 KB
testcase_14 AC 18 ms
5,692 KB
testcase_15 AC 29 ms
7,656 KB
testcase_16 AC 46 ms
9,268 KB
testcase_17 AC 61 ms
10,436 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 57 ms
9,604 KB
testcase_24 AC 22 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

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, long long> mp;
    for(int i = 0; i < n; i++){
        cin >> A[i];
        mp[A[i]]++;
    }
    if(x == 0){
        cout << (long long)n * (long long)n << endl;
        return 0;
    }

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

    long long ans = 0;
    for(int i = 0; i < n; i++){
        int r = x - A[i];
        ans += mp[r];
    }

    cout << ans << endl;

    return 0;
}
0