結果

問題 No.723 2つの数の和
ユーザー batasanblogbatasanblog
提出日時 2023-07-15 17:10:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,048 bytes
コンパイル時間 4,431 ms
コンパイル使用メモリ 269,432 KB
実行使用メモリ 8,080 KB
最終ジャッジ日時 2023-10-17 03:26:46
合計ジャッジ時間 6,468 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 33 ms
5,760 KB
testcase_04 AC 42 ms
5,968 KB
testcase_05 AC 38 ms
5,760 KB
testcase_06 AC 40 ms
5,968 KB
testcase_07 AC 19 ms
4,704 KB
testcase_08 AC 21 ms
4,780 KB
testcase_09 WA -
testcase_10 AC 18 ms
4,704 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 24 ms
4,968 KB
testcase_13 AC 43 ms
5,968 KB
testcase_14 AC 11 ms
4,348 KB
testcase_15 AC 20 ms
4,716 KB
testcase_16 AC 29 ms
5,760 KB
testcase_17 AC 37 ms
5,760 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 42 ms
8,080 KB
testcase_24 AC 14 ms
4,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
//using mint = static_modint<998244353>;
//using mint = modint;
using mint = static_modint<1000000007>;
using vm = vector<mint>;
using vvm = vector<vm>;
ostream &operator<<(ostream &o,const mint &m){cout<<m.val();return o;}
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll,ll>;
using vp = vector<pl>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define reps(i,s,n) for(ll i=(s);i<(ll)(n);++i)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);++i)
template<typename T>inline bool chmax(T &a,T b){return a<b?a=b,true:false;}
template<typename T>inline bool chmin(T &a,T b){return a>b?a=b,true:false;}
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
const long long INF = 1e18;
#ifdef DEBUG
#include <debug.hpp>
random_device rd;
mt19937 gen(rd());
ll random(ll l,ll h){
	uniform_int_distribution<ll> dist(l,h);
	return dist(gen);
}
#endif

ll N,X;
unordered_map<ll,ll> mp;
void input(){
	cin>>N>>X;
	rep(n,N){
		ll a;cin>>a;
		mp[a]++;
	}
}
#ifdef DEBUG
void showall(){
	show(N,X,mp);
}
#endif
ll logic(){
	ll ans=0;
	for(auto e:mp){
		if(e.fi + e.fi != X){
			if(mp.count(X - e.fi)) ans += mp.at(X - e.fi) * e.se;
		}else if(e.fi + e.fi == X){
			ll tmp;
			if(e.se == 1) tmp = 1;
			else tmp = e.se * (e.se-1) / 2;
			ans +=  tmp;
		}
	}
	return ans;
}
#ifdef DEBUG
ll naive(){
	return 1;
}
#endif
int main(){
	#ifdef DEBUG
	cout << "--- Input ---" << endl;
	#endif
	input();
	#ifdef DEBUG
	showall();
	cout << "--- Logic ---" << endl;
	#endif
	ll ans=logic();
	#ifdef DEBUG
	cout << "--- Answer ---" << endl;
	#endif
	cout<<ans<<endl;
	//while(input())logic();
	#ifdef DEBUG
	//show("naive=",naive());
	#endif
	#ifdef DEBUG
	/*
	rep(q,100){
		N=random(1LL,1000LL);
		showall();
		ll lans=logic(),nans=naive();
		if(lans!=nans){ show(" WA",lans,nans); break; }
		else{ show(" AC",lans,nans); }
	}
	*/
	#endif
	return 0;
}
//cout << fixed << setprecision(9);
0