結果

問題 No.723 2つの数の和
ユーザー Yut176Yut176
提出日時 2019-05-26 23:52:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 94,468 KB
実行使用メモリ 10,452 KB
最終ジャッジ日時 2023-10-17 18:06:07
合計ジャッジ時間 2,703 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 51 ms
7,020 KB
testcase_04 AC 70 ms
7,812 KB
testcase_05 AC 68 ms
7,548 KB
testcase_06 AC 69 ms
7,812 KB
testcase_07 AC 28 ms
5,704 KB
testcase_08 AC 32 ms
5,964 KB
testcase_09 AC 73 ms
7,812 KB
testcase_10 AC 28 ms
5,600 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 38 ms
6,228 KB
testcase_13 AC 72 ms
8,076 KB
testcase_14 AC 16 ms
4,964 KB
testcase_15 AC 28 ms
5,776 KB
testcase_16 AC 42 ms
6,756 KB
testcase_17 AC 57 ms
7,548 KB
testcase_18 AC 17 ms
4,348 KB
testcase_19 AC 33 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 87 ms
10,452 KB
testcase_24 AC 20 ms
5,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
long long mod = 1e9 + 7;

int main(void) {
  long long n, x; cin >> n >> x;
  vector<long long> a(n);
  map<long long, long long> m;
  for(int i=0; i<n; i++){
    cin >> a[i];
    m[a[i]]++;
  }

  long long cnt = 0;
  for(auto i=m.begin(); i!=m.end(); i++) {
    if(i->first*2 == x) {
      cnt += i->second * (i->second);
    }else{
      if(m.find(x - i->first) == m.end()) continue;
      cnt += i->second * m[x - i->first];
    }
  }
  cout << cnt << endl;
  

  return 0;
}



// EOF
0