結果

問題 No.986 Present
ユーザー risujirohrisujiroh
提出日時 2020-02-11 15:23:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 7,105 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 183,432 KB
実行使用メモリ 41,848 KB
最終ジャッジ日時 2024-10-01 07:54:13
合計ジャッジ時間 6,560 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 176 ms
21,996 KB
testcase_04 AC 21 ms
5,320 KB
testcase_05 AC 147 ms
18,304 KB
testcase_06 AC 99 ms
13,748 KB
testcase_07 AC 5 ms
5,248 KB
testcase_08 AC 52 ms
9,216 KB
testcase_09 AC 202 ms
24,968 KB
testcase_10 AC 3 ms
5,248 KB
testcase_11 AC 132 ms
17,972 KB
testcase_12 AC 100 ms
15,052 KB
testcase_13 AC 4 ms
5,248 KB
testcase_14 AC 17 ms
5,248 KB
testcase_15 AC 315 ms
35,160 KB
testcase_16 AC 65 ms
9,372 KB
testcase_17 AC 209 ms
25,932 KB
testcase_18 AC 165 ms
20,072 KB
testcase_19 AC 103 ms
14,532 KB
testcase_20 AC 6 ms
5,248 KB
testcase_21 AC 312 ms
36,024 KB
testcase_22 AC 236 ms
28,860 KB
testcase_23 AC 92 ms
13,844 KB
testcase_24 AC 361 ms
41,848 KB
testcase_25 AC 47 ms
8,704 KB
testcase_26 AC 335 ms
40,124 KB
testcase_27 AC 203 ms
26,584 KB
testcase_28 AC 108 ms
13,676 KB
testcase_29 AC 106 ms
13,308 KB
testcase_30 AC 5 ms
5,248 KB
testcase_31 AC 109 ms
13,072 KB
testcase_32 AC 109 ms
13,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class T> vector<T> operator-(vector<T> a) {
  for (auto&& e : a) e = -e;
  return a;
}
template <class T> vector<T>& operator+=(vector<T>& l, const vector<T>& r) {
  l.resize(max(l.size(), r.size()));
  for (int i = 0; i < (int)r.size(); ++i) l[i] += r[i];
  return l;
}
template <class T> vector<T> operator+(vector<T> l, const vector<T>& r) {
  return l += r;
}
template <class T> vector<T>& operator-=(vector<T>& l, const vector<T>& r) {
  l.resize(max(l.size(), r.size()));
  for (int i = 0; i < (int)r.size(); ++i) l[i] -= r[i];
  return l;
}
template <class T> vector<T> operator-(vector<T> l, const vector<T>& r) {
  return l -= r;
}
template <class T> vector<T>& operator<<=(vector<T>& a, size_t n) {
  return a.insert(begin(a), n, 0), a;
}
template <class T> vector<T> operator<<(vector<T> a, size_t n) {
  return a <<= n;
}
template <class T> vector<T>& operator>>=(vector<T>& a, size_t n) {
  return a.erase(begin(a), begin(a) + min(a.size(), n)), a;
}
template <class T> vector<T> operator>>(vector<T> a, size_t n) {
  return a >>= n;
}
template <class T> vector<T> operator*(const vector<T>& l, const vector<T>& r) {
  if (l.empty() or r.empty()) return {};
  vector<T> res(l.size() + r.size() - 1);
  for (int i = 0; i < (int)l.size(); ++i)
    for (int j = 0; j < (int)r.size(); ++j) res[i + j] += l[i] * r[j];
  return res;
}
template <class T> vector<T>& operator*=(vector<T>& l, const vector<T>& r) {
  return l = l * r;
}
template <class T> vector<T> inverse(const vector<T>& a) {
  assert(not a.empty() and not (a[0] == 0));
  vector<T> b{1 / a[0]};
  while (b.size() < a.size()) {
    vector<T> x(begin(a), begin(a) + min(a.size(), 2 * b.size()));
    x *= b * b;
    b.resize(2 * b.size());
    for (auto i = b.size() / 2; i < min(x.size(), b.size()); ++i) b[i] = -x[i];
  }
  return {begin(b), begin(b) + a.size()};
}
template <class T> vector<T> operator/(vector<T> l, vector<T> r) {
  if (l.size() < r.size()) return {};
  reverse(begin(l), end(l)), reverse(begin(r), end(r));
  int n = l.size() - r.size() + 1;
  l.resize(n), r.resize(n);
  l *= inverse(r);
  return {rend(l) - n, rend(l)};
}
template <class T> vector<T>& operator/=(vector<T>& l, const vector<T>& r) {
  return l = l / r;
}
template <class T> vector<T> operator%(vector<T> l, const vector<T>& r) {
  if (l.size() < r.size()) return l;
  l -= l / r * r;
  return {begin(l), begin(l) + (r.size() - 1)};
}
template <class T> vector<T>& operator%=(vector<T>& l, const vector<T>& r) {
  return l = l % r;
}
template <class T> vector<T> derivative(const vector<T>& a) {
  vector<T> res(max((int)a.size() - 1, 0));
  for (int i = 0; i < (int)res.size(); ++i) res[i] = (i + 1) * a[i + 1];
  return res;
}
template <class T> vector<T> primitive(const vector<T>& a) {
  vector<T> res(a.size() + 1);
  for (int i = 1; i < (int)res.size(); ++i) res[i] = a[i - 1] / i;
  return res;
}
template <class T> vector<T> logarithm(const vector<T>& a) {
  assert(not a.empty() and a[0] == 1);
  auto res = primitive(derivative(a) * inverse(a));
  return {begin(res), begin(res) + a.size()};
}
template <class T> vector<T> exponent(const vector<T>& a) {
  assert(a.empty() or a[0] == 0);
  vector<T> b{1};
  while (b.size() < a.size()) {
    vector<T> x(begin(a), begin(a) + min(a.size(), 2 * b.size()));
    x[0] += 1;
    b.resize(2 * b.size());
    x -= logarithm(b);
    x *= {begin(b), begin(b) + b.size() / 2};
    for (auto i = b.size() / 2; i < min(x.size(), b.size()); ++i) b[i] = x[i];
  }
  return {begin(b), begin(b) + a.size()};
}

template <class T, class F = multiplies<T>>
T power(T a, long long n, F op = multiplies<T>(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  unsigned v;
  modular(long long a = 0) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m r) { if ((v += r.v) >= M) v -= M; return *this; }
  m& operator-=(m r) { if (v < r.v) v += M; v -= r.v; return *this; }
  m& operator*=(m r) { v = (uint64_t)v * r.v % M; return *this; }
  m& operator/=(m r) { return *this *= power(r, M - 2); }
  friend m operator+(m l, m r) { return l += r; }
  friend m operator-(m l, m r) { return l -= r; }
  friend m operator*(m l, m r) { return l *= r; }
  friend m operator/(m l, m r) { return l /= r; }
  friend bool operator==(m l, m r) { return l.v == r.v; }
};

template <unsigned M> void ntt(vector<modular<M>>& a, bool inverse) {
  static vector<modular<M>> dw(30), idw(30);
  if (dw[0] == 0) {
    modular<M> root = 2;
    while (power(root, (M - 1) / 2) == 1) root += 1;
    for (int i = 0; i < 30; ++i)
      dw[i] = -power(root, (M - 1) >> (i + 2)), idw[i] = 1 / dw[i];
  }
  int n = a.size();
  assert((n & (n - 1)) == 0);
  if (not inverse) {
    for (int m = n; m >>= 1; ) {
      modular<M> w = 1;
      for (int s = 0, k = 0; s < n; s += 2 * m) {
        for (int i = s, j = s + m; i < s + m; ++i, ++j) {
          auto x = a[i], y = a[j] * w;
          if (x.v >= M) x.v -= M;
          a[i].v = x.v + y.v, a[j].v = x.v + (M - y.v);
        }
        w *= dw[__builtin_ctz(++k)];
      }
    }
  } else {
    for (int m = 1; m < n; m *= 2) {
      modular<M> w = 1;
      for (int s = 0, k = 0; s < n; s += 2 * m) {
        for (int i = s, j = s + m; i < s + m; ++i, ++j) {
          auto x = a[i], y = a[j];
          a[i] = x + y, a[j].v = x.v + (M - y.v), a[j] *= w;
        }
        w *= idw[__builtin_ctz(++k)];
      }
    }
  }
  auto c = 1 / modular<M>(inverse ? n : 1);
  for (auto&& e : a) e *= c;
}
template <unsigned M>
vector<modular<M>> operator*(vector<modular<M>> l, vector<modular<M>> r) {
  if (l.empty() or r.empty()) return {};
  int n = l.size(), m = r.size(), sz = 1 << __lg(2 * (n + m - 1) - 1);
  if (min(n, m) < 30) {
    vector<long long> res(n + m - 1);
    for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j)
      res[i + j] += (l[i] * r[j]).v;
    return {begin(res), end(res)};
  }
  bool eq = l == r;
  l.resize(sz), ntt(l, false);
  if (eq) r = l;
  else r.resize(sz), ntt(r, false);
  for (int i = 0; i < sz; ++i) l[i] *= r[i];
  ntt(l, true), l.resize(n + m - 1);
  return l;
}

constexpr long long mod = 998244353;
using mint = modular<mod>;

mint fn(int n, int m) {
  mint res = 1;
  for (int i = 0; i < n; ++i) {
    res *= power(mint(2), m) - power(mint(2), i);
    res /= i + 1;
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<mint>> t(2 * n);
  for (int i = 0; i < n; ++i) {
    t[n + i] = {1, -power(mint(2), i + 1)};
  }
  for (int i = n; i-- > 1; ) {
    t[i] = t[2 * i] * t[2 * i + 1];
  }
  vector<mint> a{1};
  for (int l = n, r = 2 * n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      a *= t[l++];
    }
    if (r & 1) {
      a *= t[--r];
    }
  }
  a.resize(m - n + 1);
  a = inverse(a);
  mint res = accumulate(begin(a), end(a), mint(0));
  cout << power(mint(2), n).v << ' ' << fn(n, m).v << ' ' << res.v << '\n';
}
0