結果

問題 No.723 2つの数の和
ユーザー shirokamishirokami
提出日時 2021-07-07 16:49:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 5,786 bytes
コンパイル時間 8,706 ms
コンパイル使用メモリ 466,216 KB
実行使用メモリ 6,176 KB
最終ジャッジ日時 2023-09-14 04:38:05
合計ジャッジ時間 9,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
5,980 KB
testcase_01 AC 20 ms
5,780 KB
testcase_02 AC 20 ms
5,776 KB
testcase_03 AC 26 ms
5,792 KB
testcase_04 AC 29 ms
5,912 KB
testcase_05 AC 28 ms
5,856 KB
testcase_06 AC 28 ms
5,852 KB
testcase_07 AC 23 ms
5,992 KB
testcase_08 AC 24 ms
5,984 KB
testcase_09 AC 29 ms
5,980 KB
testcase_10 AC 23 ms
5,984 KB
testcase_11 AC 21 ms
5,848 KB
testcase_12 AC 25 ms
6,176 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 21 ms
6,084 KB
testcase_21 AC 20 ms
5,976 KB
testcase_22 AC 20 ms
5,796 KB
testcase_23 AC 29 ms
5,924 KB
testcase_24 AC 23 ms
5,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <atcoder/all>
using namespace atcoder;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;
using P = pair<ll,ll>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} iosetup;

template<class T>
struct FormalPowerSeries : vector<T> {
  using vector<T>::vector;
  using vector<T>::operator=;
  using F = FormalPowerSeries;

  F operator-() const {
    F res(*this);
    for (auto &e : res) e = -e;
    return res;
  }
  F &operator*=(const T &g) {
    for (auto &e : *this) e *= g;
    return *this;
  }
  F &operator/=(const T &g) {
    assert(g != T(0));
    *this *= g.inv();
    return *this;
  }
  F &operator+=(const F &g) {
    ll n = (*this).size(), m = g.size();
    rep(i, min(n, m)) (*this)[i] += g[i];
    return *this;
  }
  F &operator-=(const F &g) {
    ll n = (*this).size(), m = g.size();
    rep(i, min(n, m)) (*this)[i] -= g[i];
    return *this;
  }
  F &operator<<=(const ll d) {
    ll n = (*this).size();
    (*this).insert((*this).begin(), d, 0);
    (*this).resize(n);
    return *this;
  }
  F &operator>>=(const ll d) {
    ll n = (*this).size();
    (*this).erase((*this).begin(), (*this).begin() + min(n, d));
    (*this).resize(n);
    return *this;
  }
  F inv(ll d = -1) const {
    ll n = (*this).size();
    assert(n != 0 && (*this)[0] != 0);
    if (d == -1) d = n;
    assert(d > 0);
    F res{(*this)[0].inv()};
    while (res.size() < d) {
      ll m = size(res);
      F f(begin(*this), begin(*this) + min(n, 2*m));
      F r(res);
      f.resize(2*m), internal::butterfly(f);
      r.resize(2*m), internal::butterfly(r);
      rep(i, 2*m) f[i] *= r[i];
      internal::butterfly_inv(f);
      f.erase(f.begin(), f.begin() + m);
      f.resize(2*m), internal::butterfly(f);
      rep(i, 2*m) f[i] *= r[i];
      internal::butterfly_inv(f);
      T iz = T(2*m).inv(); iz *= -iz;
      rep(i, m) f[i] *= iz;
      res.insert(res.end(), f.begin(), f.begin() + m);
    }
    return {res.begin(), res.begin() + d};
  }

   // fast: FMT-friendly modulus only
   F &operator*=(const F &g) {
     ll n = (*this).size();
     *this = convolution(*this, g);
     (*this).resize(n);
     return *this;
   }
   F &operator/=(const F &g) {
     ll n = (*this).size();
     *this = convolution(*this, g.inv(n));
     (*this).resize(n);
     return *this;
   }

  // // naive
  // F &operator*=(const F &g) {
  //   ll n = (*this).size(), m = g.size();
  //   for (ll i = n-1; i >= 0; --i) {
  //     (*this)[i] *= g[0];
  //     Rep(j, 1, min(i+1, m)) (*this)[i] += (*this)[i-j] * g[j];
  //   }
  //   return *this;
  // }
  // F &operator/=(const F &g) {
  //   assert(g[0] != T(0));
  //   T ig0 = g[0].inv();
  //   ll n = (*this).size(), m = g.size();
  //   rep(i, n) {
  //     Rep(j, 1, min(i+1, m)) (*this)[i] -= (*this)[i-j] * g[j];
  //     (*this)[i] *= ig0;
  //   }
  //   return *this;
  // }

  // sparse
  F &operator*=(vector<pair<ll, T>> g) {
    ll n = (*this).size();
    auto [d, c] = g.front();
    if (d == 0) g.erase(g.begin());
    else c = 0;
    for (ll i = n-1; i >= 0; --i) {
      (*this)[i] *= c;
      for (auto &[j, b] : g) {
        if (j > i) break;
        (*this)[i] += (*this)[i-j] * b;
      }
    }
    return *this;
  }
  F &operator/=(vector<pair<ll, T>> g) {
    ll n = (*this).size();
    auto [d, c] = g.front();
    assert(d == 0 && c != T(0));
    T ic = c.inv();
    g.erase(g.begin());
    rep(i, n) {
      for (auto &[j, b] : g) {
        if (j > i) break;
        (*this)[i] -= (*this)[i-j] * b;
      }
      (*this)[i] *= ic;
    }
    return *this;
  }

  // multiply and divide (1 + cz^d)
  void multiply(const ll d, const T c) { 
    ll n = (*this).size();
    if (c == T(1)) for (ll i = n-d-1; i >= 0; --i) (*this)[i+d] += (*this)[i];
    else if (c == T(-1)) for (ll i = n-d-1; i >= 0; --i) (*this)[i+d] -= (*this)[i];
    else for (ll i = n-d-1; i >= 0; --i) (*this)[i+d] += (*this)[i] * c;
  }
  void divide(const ll d, const T c) {
    ll n = (*this).size();
    if (c == T(1)) rep(i, n-d) (*this)[i+d] -= (*this)[i];
    else if (c == T(-1)) rep(i, n-d) (*this)[i+d] += (*this)[i];
    else rep(i, n-d) (*this)[i+d] -= (*this)[i] * c;
  }

  T eval(const T &a) const {
    T x(1), res(0);
    for (auto e : *this) res += e * x, x *= a;
    return res;
  }

  F operator*(const T &g) const { return F(*this) *= g; }
  F operator/(const T &g) const { return F(*this) /= g; }
  F operator+(const F &g) const { return F(*this) += g; }
  F operator-(const F &g) const { return F(*this) -= g; }
  F operator<<(const ll d) const { return F(*this) <<= d; }
  F operator>>(const ll d) const { return F(*this) >>= d; }
  F operator*(const F &g) const { return F(*this) *= g; }
  F operator/(const F &g) const { return F(*this) /= g; }
  F operator*(vector<pair<ll, T>> g) const { return F(*this) *= g; }
  F operator/(vector<pair<ll, T>> g) const { return F(*this) /= g; }
};

using mint = modint998244353;
using fps = FormalPowerSeries<mint>;
using sfps = vector<pair<ll, mint>>;

int main() {
  ll n, x;
  cin >> n >> x;
  fps f(101000);
  rep(i,n) {
    ll a;
    cin >> a;
    f[a]++;
  }
  f *= f;
  cout << f[x].val() << '\n';
}
0