結果

問題 No.723 2つの数の和
ユーザー d_seid_sei
提出日時 2019-11-16 16:52:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,102 bytes
コンパイル時間 1,133 ms
コンパイル使用メモリ 102,284 KB
実行使用メモリ 4,928 KB
最終ジャッジ日時 2023-10-25 04:52:56
合計ジャッジ時間 2,646 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
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 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/


int main() {
	lint N, X;
	cin >> N >> X;
	vector<lint>a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	lint cnt = 0;
	for (int i = 1; i < N; i++) {
		if (a[i - 1] == a[i]) {
			a[i - 1] = -1;
			cnt++;
		}
	}
	lint n = N - cnt;
	vector<lint>A(n);
	lint cnt2 = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] != -1) {
			A[cnt2] = a[i];
			cnt2++;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << A[i] << ' ';
	}
	cout << endl;



	lint serch;
	lint left;
	lint right;
	lint ans = 0;
	for (int i = 0; i < n; i++) {
		serch = X - A[i];
		left = 0;
		right = n - 1;
		 do{
			int mid = (left + right) / 2;
			if (serch == A[mid]) {
				ans++;
				break;
			}
			else if (serch < A[mid]) {
				right = mid;
			}
			else if (serch > A[mid]) {
				left = mid;
			}
			else if (serch == A[0]) {
				ans++;
				break;
			}
			else if (serch == A[n - 1]) {
				ans++;
				break;
			}
			else if (serch == A[right]) {
				ans++;
				break;
			}
			else if (serch == A[left]) {
				ans++;
				break;
			}
		 } while (right - left != 0 && right - left != 1);
	}
	cout << ans << endl;
	
		/*int a[] = { 0,1,2,3,4,5,6,7,8,9 };

		int serch = 9;

		int right = 0, left = 9;

		while (right < left)
		{
			printf("a");
			int mid = (left + right) / 2;

			if (serch == a[mid])
			{
				printf("%dは%d番目", serch, mid);
				break;
			}
			else if (serch > a[mid])
				right = mid;
			else if (serch < a[mid])
				left = mid;
		}*/
}
0