結果

問題 No.723 2つの数の和
ユーザー GBGB
提出日時 2018-12-18 12:25:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 794 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 66,888 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 23:38:06
合計ジャッジ時間 19,756 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,779 ms
4,348 KB
testcase_14 AC 86 ms
4,348 KB
testcase_15 AC 282 ms
4,348 KB
testcase_16 AC 675 ms
4,348 KB
testcase_17 AC 1,119 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1,699 ms
4,348 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool binary_search(int key,vector<int> a) {
	int left = 0, right = (int)a.size() - 1; // 配列 a の左端と右端
	while (right >= left) {
		int mid = left + (right - left) / 2; // 区間の真ん中
		if (a[mid] == key) return true;//値を返す
		else if (a[mid] > key) right = mid - 1;
		else if (a[mid] < key) left = mid + 1;
	}
	return false;
}


int main() {

	int n, x;
	int count = 0;//数え上げる変数
	cin >> n >> x;
	vector<int> data;
	for (int i = 0;i < n;i++) {
		int buff = 0;
		cin >> buff;
		data.push_back(buff);
	}
	sort(data.begin(),data.end());
	for (int i = 0;i < n;i++) {
		int target = x - data[i];
		if (binary_search(target, data))count++;
	}
	cout << count << endl;

	return 0;
}
0