結果

問題 No.723 2つの数の和
ユーザー aaa
提出日時 2018-11-08 22:52:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,348 bytes
コンパイル時間 900 ms
コンパイル使用メモリ 100,500 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-20 21:09:41
合計ジャッジ時間 2,262 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 14 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;


int main(){
	int i, j, k;
	long long n, x;
	vector<bool>flag(100009, false);
	vector<long long>list;
	vector<int>list2(100005, 0);
	long cnt2 = 0;

	cin >> n >> x;


	for (i = 0; i < n; i++) {
		long long num;
		cin >> num;

		if (num <= 100000) {
			list2[num]++;
		}

		if ( (x - num > 100000) || (x - num < 0)) {

		}
		else {
			//if (flag[x - num] == true) cnt2++;
			flag[x - num] = true;
		}

		list.push_back(num);

	}

	long sum = 0;

	for (i = 0; i < 100000; i++) {
		if (x - i == i) {
			while(list2[i]>=2)
			{
				sum += list2[i] * (list2[i] - 1);
				list2[i]--;
			}
			//sum--;
			continue;
		}

		if (x - i <= 100000 && x - i >= 0) {
			sum += (list2[i] * list2[x - i]);
		}
	}

	cout << sum << endl;


	//long long cnt = 0;

	//sort(list.begin(), list.end());

	//for (i = 0; i < n; i++) {
	//	if (flag[list[i]] == true) {
	//		if ( i != 0 && list[i] == list[i - 1]) cnt2++;
	//		cnt++;
	//	}
	//}

	//cout << cnt + cnt2 << endl;










	getchar();
	getchar();
	return 0;
}
0