結果

問題 No.8046 yukicoderの過去問
ユーザー risujirohrisujiroh
提出日時 2019-04-02 06:15:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,585 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 182,580 KB
実行使用メモリ 21,184 KB
最終ジャッジ日時 2024-11-27 20:40:59
合計ジャッジ時間 10,366 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,248 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,248 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

using R = long double;
constexpr R pi = acos(-1.0L);
using C = complex<R>;
C& operator*=(C& l, const C& r) {
  return l = {real(l) * real(r) - imag(l) * imag(r), real(l) * imag(r) + imag(l) * real(r)};
}
void fft(V<C>& a, bool inv = false) {
  int n = a.size();
  int j = 0;
  for (int i = 1; i < n; ++i) {
    int k = n >> 1;
    while (j >= k) j -= k, k >>= 1;
    j += k;
    if (i < j) swap(a[i], a[j]);
  }
  for (int k = 1; k < n; k <<= 1) {
    C dt = polar<R>(1, (inv ? -pi : pi) / k);
    for (int i0 = 0; i0 < n; i0 += k << 1) {
      C t = 1;
      for (int i = i0; i < i0 + k; ++i) {
        j = i + k;
        a[j] *= t, t *= dt;
        tie(a[i], a[j]) = make_pair(a[i] + a[j], a[i] - a[j]);
      }
    }
  }
}
template<class Z> void multiply(V<Z>& a, const V<Z>& b) {
  assert(!a.empty() and !b.empty());
  int n = 1 << __lg(2 * (a.size() + b.size() - 1) - 1);
  V<C> c(n);
  for (int i = 0; i < n; ++i) {
    if (i < (int) a.size()) c[i].real(a[i]);
    if (i < (int) b.size()) c[i].imag(b[i]);
  }
  fft(c);
  for (int i = 0; i <= n / 2; ++i) {
    c[i] *= c[i];
    if (i & n / 2 - 1) c[n - i] *= c[n - i];
    c[i] = C(0, -0.25) * (c[i] - conj(c[n - i & n - 1]));
    if (i & n / 2 - 1) c[n - i] = conj(c[i]);
  }
  fft(c, true);
  a.resize(a.size() + b.size() - 1);
  for (int i = 0; i < (int) a.size(); ++i) {
    a[i] = real(c[i]) / n + 0.5;
  }
}

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  template<class Z> ModInt(Z x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool) *this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t) v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  template<class Z> M pow(Z n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  template<class Z> friend M operator*(Z l, M r) { return M(l) *= r; }
  template<class Z> friend M operator/(Z l, M r) { return M(l) /= r; }
  template<class Z> friend M operator+(Z l, M r) { return M(l) += r; }
  template<class Z> friend M operator-(Z l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  template<class Z> friend bool operator==(Z l, M r) { return M(l) == r; }
  template<class Z> friend bool operator!=(Z l, M r) { return !(l == r); }
};
using Mint = ModInt<(unsigned) 1e9 + 7>;
using Z = lint;
void multiply(V<Mint>& a, const V<Mint>& b) {
  int n = a.size(), m = b.size();
  V<Z> _a(n), _b(m);
  for (int i = 0; i < n; ++i) _a[i] = a[i].v;
  for (int j = 0; j < m; ++j) _b[j] = b[j].v;
  multiply(_a, _b);
  n = _a.size();
  a.resize(n);
  for (int i = 0; i < n; ++i) a[i] = _a[i];
}

template<class T> struct Polynomial {
  using P = Polynomial;
  V<T> c;
  Polynomial(int n = 0) : c(n) {}
  void shrink() { while (!c.empty() and !c.back()) c.pop_back(); }
  int size() const { return c.size(); }
  T& operator[](int i) { return c[i]; }
  const T& operator[](int i) const { return c[i]; }
  P operator*(const P& r) const { return P(*this) *= r; }
  P operator*(const T& r) const { return P(*this) *= r; }
  P operator/(const P& r) const { return P(*this) /= r; }
  P operator+(const P& r) const { return P(*this) += r; }
  P operator-(const P& r) const { return P(*this) -= r; }
  P& operator*=(const T& r) {
    for (int i = 0; i < size(); ++i) c[i] *= r;
    shrink();
    return *this;
  }
  P& operator*=(const P& r) { multiply(c, r.c), shrink(); return *this; }
  P& operator/=(const P& r) { return *this *= r.inverse(); }
  P& operator+=(const P& r) {
    if (r.size() > size()) c.resize(r.size());
    for (int i = 0; i < r.size(); ++i) c[i] += r[i];
    shrink();
    return *this;
  }
  P& operator-=(const P& r) {
    if (r.size() > size()) c.resize(r.size());
    for (int i = 0; i < r.size(); ++i) c[i] -= r[i];
    shrink();
    return *this;
  }
  P inverse(int n) const {
    assert(!c.empty() and c[0]);
    if (n == 1) {
      P res(1);
      res[0] = 1 / c[0];
      return res;
    }
    P inv = inverse(n + 1 >> 1);
    P res = inv * (T) 2 - *this * inv * inv;
    res.c.resize(n);
    return res;
  }
};
using P = Polynomial<Mint>;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int k, n; cin >> k >> n;
  P f(1e5 + 1);
  f[0] = 1;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    f[x] = -1;
  }
  f.shrink();
  cout << f.inverse(k + 1)[k] << '\n';
}
0