結果

問題 No.723 2つの数の和
ユーザー TomoyoshiTatsumi
提出日時 2025-03-25 09:38:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 6,472 bytes
コンパイル時間 4,353 ms
コンパイル使用メモリ 252,980 KB
実行使用メモリ 14,776 KB
最終ジャッジ日時 2025-03-25 09:38:39
合計ジャッジ時間 8,344 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other TLE * 1 -- * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:64: warning: "rep" redefined
   64 | #define rep(i, n) rep2(i, 0, n)
      | 
main.cpp:8: note: this is the location of the previous definition
    8 | #define rep(i, n) for (int i = 0; (i) < (int)(n); ++(i))
      | 

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

#define isin(l, x, r) (l <= x && x < r)
#define rep(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define rep_r(i, n) for (int i = (int)(n) - 1; (i) >= 0; --(i))
#define rep3r(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); --(i))
#define all(x) begin(x), end(x)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using ll = long long;
using PI = std::pair<int, int>;
using PLL = std::pair<ll, ll>;
using VI = std::vector<int>;
using VLL = std::vector<ll>;

template <typename T>
using PQ = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

/*
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
cout << std::fixed << std::setprecision(15) << y << endl;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
*/

/*
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
*/

#ifdef LOCAL
// #include <debug.h>
#else
#define dlog(...)
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m) - 1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)

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) {
    int n = (*this).size(), m = g.size();
    rep(i, min(n, m))(*this)[i] += g[i];
    return *this;
  }
  F &operator-=(const F &g) {
    int n = (*this).size(), m = g.size();
    rep(i, min(n, m))(*this)[i] -= g[i];
    return *this;
  }
  F &operator<<=(const int d) {
    int n = (*this).size();
    (*this).insert((*this).begin(), d, 0);
    (*this).resize(n);
    return *this;
  }
  F &operator>>=(const int d) {
    int n = (*this).size();
    (*this).erase((*this).begin(), (*this).begin() + min(n, d));
    (*this).resize(n);
    return *this;
  }
  F inv(int d = -1) const {
    int 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) {
      int 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};
  }

  // // naive
  F &operator*=(const F &g) {
    int n = (*this).size(), m = g.size();
    drep(i, n) {
      (*this)[i] *= g[0];
      rep2(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();
    int n = (*this).size(), m = g.size();
    rep(i, n) {
      rep2(j, 1, min(i + 1, m))(*this)[i] -= (*this)[i - j] * g[j];
      (*this)[i] *= ig0;
    }
    return *this;
  }

  // sparse
  F &operator*=(vector<pair<int, T>> g) {
    int n = (*this).size();
    auto [d, c] = g.front();
    if (d == 0) g.erase(g.begin());
    else c = 0;
    drep(i, n) {
      (*this)[i] *= c;
      for (auto &[j, b] : g) {
        if (j > i) break;
        (*this)[i] += (*this)[i - j] * b;
      }
    }
    return *this;
  }
  F &operator/=(vector<pair<int, T>> g) {
    int 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 int d, const T c) {
    int n = (*this).size();
    if (c == T(1)) drep(i, n - d)(*this)[i + d] += (*this)[i];
    else if (c == T(-1)) drep(i, n - d)(*this)[i + d] -= (*this)[i];
    else drep(i, n - d)(*this)[i + d] += (*this)[i] * c;
  }
  void divide(const int d, const T c) {
    int 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 int d) const {
    return F(*this) <<= d;
  }
  F operator>>(const int 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<int, T>> g) const {
    return F(*this) *= g;
  }
  F operator/(vector<pair<int, T>> g) const {
    return F(*this) /= g;
  }
};

ll solve(int N, ll K, const std::vector<ll> &A) {
  auto mx = *max_element(all(A));
  FormalPowerSeries<ll> ans(2 * mx + 10, 0);
  rep(i, N) ans[A[i]]++;
  ans *= ans;
  return ans[K];
}

// generated by oj-template v4.8.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << std::fixed << std::setprecision(15);
  int n;
  ll k;
  std::cin >> n;
  std::vector<ll> a(n);
  std::cin >> k;
  rep(i, n) {
    std::cin >> a[i];
  }
  auto ans = solve(n, k, a);
  std::cout << ans << '\n';
  return 0;
}
0