結果
問題 | No.723 2つの数の和 |
ユーザー |
![]() |
提出日時 | 2023-07-15 17:41:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 2,386 bytes |
コンパイル時間 | 4,337 ms |
コンパイル使用メモリ | 258,588 KB |
最終ジャッジ日時 | 2025-02-15 15:07:17 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#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; vl A; unordered_map<ll,ll> mp; void input(){ cin>>N>>X; A.assign(N,0); rep(n,N)cin>>A.at(n); } #ifdef DEBUG void showall(){ show(N,X,A); } #endif ll logic(){ mp.clear(); rep(n,N){ mp[A.at(n)]++; } ll ans=0; for(auto e:mp){ if(mp.count(X - e.fi)) ans += mp.at(X - e.fi) * e.se; /** 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(){ ll MX=100001; vl v(MX,0); rep(n,N){ v.at(A.at(n))++; } vl w = convolution_ll(v,v); ll ans; if(X < w.size()) ans=w.at(X); else ans = 0; return ans; } #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,20); X=random(1LL,100); A.assign(N,0); rep(n,N){ A.at(n) = random(1LL,10); } 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);