結果

問題 No.723 2つの数の和
ユーザー tokizotokizo
提出日時 2019-03-09 10:35:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 589 bytes
コンパイル時間 1,662 ms
コンパイル使用メモリ 175,176 KB
実行使用メモリ 8,104 KB
最終ジャッジ日時 2023-09-05 19:48:20
合計ジャッジ時間 3,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 39 ms
5,720 KB
testcase_04 AC 54 ms
6,488 KB
testcase_05 AC 46 ms
6,072 KB
testcase_06 AC 51 ms
6,140 KB
testcase_07 AC 20 ms
4,880 KB
testcase_08 AC 24 ms
5,004 KB
testcase_09 AC 51 ms
6,216 KB
testcase_10 AC 21 ms
4,896 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 27 ms
5,272 KB
testcase_13 AC 51 ms
6,652 KB
testcase_14 AC 12 ms
4,648 KB
testcase_15 AC 20 ms
5,100 KB
testcase_16 AC 31 ms
5,596 KB
testcase_17 AC 42 ms
6,064 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 54 ms
8,104 KB
testcase_24 AC 15 ms
4,416 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, 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