結果

問題 No.723 2つの数の和
ユーザー takiteketakiteke
提出日時 2018-08-03 23:04:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 79,016 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 21:37:37
合計ジャッジ時間 2,217 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 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 AC 5 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 36 ms
4,348 KB
testcase_14 AC 10 ms
4,348 KB
testcase_15 AC 16 ms
4,348 KB
testcase_16 AC 23 ms
4,348 KB
testcase_17 AC 30 ms
4,348 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 31 ms
4,348 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int N, X;
int a[100005];
int ans;
signed main() {
	cin >> N >> X;
	for (int i = 0;i < N;i++) {
		cin >> a[i];
	}
	sort(a, a+N);
	ans = 0;
	int l = 0;
	int r = N - 1;
	while (l < r) {
		int tmp = a[l] + a[r];
		//cout << tmp << endl;
		if (tmp < X) l++;
		else if (tmp > X) r--;
		else if (tmp == X) {
			ans++;
			while (a[l] == a[l + 1] && l < N-1) {
				l++;
				ans++;
			}
			while (a[r] == a[r - 1] && r > 0) {
				r--;
				ans++;
			}
			l++;
		}
	}
	ans *= 2;
	if (a[l] + a[r] == X)ans++;

	cout << ans << endl;
	return 0;
}
0