結果

問題 No.723 2つの数の和
ユーザー d_seid_sei
提出日時 2019-11-16 17:25:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 1,338 ms
コンパイル使用メモリ 101,572 KB
実行使用メモリ 4,928 KB
最終ジャッジ日時 2023-10-25 05:55:50
合計ジャッジ時間 3,007 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 28 ms
4,664 KB
testcase_04 AC 38 ms
4,928 KB
testcase_05 AC 34 ms
4,664 KB
testcase_06 AC 36 ms
4,928 KB
testcase_07 AC 17 ms
4,400 KB
testcase_08 AC 19 ms
4,400 KB
testcase_09 AC 37 ms
4,928 KB
testcase_10 AC 17 ms
4,400 KB
testcase_11 AC 6 ms
4,372 KB
testcase_12 AC 22 ms
4,664 KB
testcase_13 AC 38 ms
4,928 KB
testcase_14 AC 11 ms
4,400 KB
testcase_15 AC 17 ms
4,400 KB
testcase_16 AC 24 ms
4,664 KB
testcase_17 AC 32 ms
4,664 KB
testcase_18 AC 19 ms
4,928 KB
testcase_19 AC 34 ms
4,928 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 3 ms
4,372 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 36 ms
4,928 KB
testcase_24 AC 13 ms
4,400 KB
権限があれば一括ダウンロードができます

ソースコード

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());
	
	vector<lint>s(100000);
	for (int i = 0; i < n; i++) {
		s[A[i]]++;
	}


	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;
		while (right - left >= 0){
			lint mid = (left + right) / 2;
			if (serch == A[mid]) {
				ans+=s[A[mid]];
				break;
			}
			else if (serch < A[mid]) {
				right = mid-1;
			}
			else if (serch > A[mid]) {
				left = mid+1;
			}
			
		 } 
	}
	cout << ans << endl;
	
		
}
0