結果

問題 No.723 2つの数の和
ユーザー ajiruajiru
提出日時 2020-02-09 08:07:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 449 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 74,772 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-01 05:45:29
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	int n, x;
	cin >> n >> x;
	vector<int> A(n);
	for (int i = 0; i < n; ++i) cin >> A[i];
	sort(A.begin(), A.end());

	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		int key = x - A[i];
		auto itr1 = lower_bound(A.begin(), A.end(), key);
		auto itr2 = upper_bound(A.begin(), A.end(), key);
		ans += itr2 - itr1;
	}
	cout << ans << endl;
	return 0;
}
0