Language: C++


#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <uint32_t Modulus>
class modular {
public:
  using value_type = uint32_t;
  using max_type = uint64_t;

  static constexpr value_type mod = Modulus;
  static constexpr value_type mod_min = 1;
  static constexpr value_type mod_max = 2147483647;
  static_assert(mod >= mod_min, "invalid mod :: too small");
  static_assert(mod <= mod_max, "invalid mod :: too big");

  template <class T>
  static constexpr value_type normalize(T value_) {
    if (value_ < 0) {
      value_ = -value_;
      value_ %= mod;
      if (value_ == 0) return 0;
      return mod - value_;
    }
    return value_ % mod;
  }

private:
  value_type value;

public:
  constexpr modular(): value(0) { }
  template <class T>
  explicit constexpr modular(T value_): value(normalize(value_)) { }
  template <class T>
  explicit constexpr operator T() { return static_cast<T>(value); }

  constexpr value_type operator () () const { return value; }
  constexpr modular operator - () const { return modular(mod - value); }
  constexpr modular operator ~ () const { return inverse(); }

  constexpr value_type &extract() { return value; }
  constexpr modular inverse() const { return power(mod - 2); }
  constexpr modular power(max_type exp) const {
    modular res(1), mult(*this);
    while (exp > 0) {
      if (exp & 1) res *= mult;
      mult *= mult;
      exp >>= 1;
    }
    return res;
  }

  constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; }
  constexpr modular& operator += (const modular &rhs) { 
    if ((value += rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; }
  constexpr modular& operator -= (const modular &rhs) { 
    if ((value += mod - rhs.value) >= mod) value -= mod; 
    return *this; 
  }

  constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; }
  constexpr modular& operator *= (const modular &rhs) { 
    value = (max_type) value * rhs.value % mod;
    return *this;
  }

  constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; }
  constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); }

  constexpr bool zero() const { return value == 0; }
  constexpr bool operator == (const modular &rhs) const { return value == rhs.value; }
  constexpr bool operator != (const modular &rhs) const { return value != rhs.value; }
  friend std::ostream& operator << (std::ostream &stream, const modular &rhs) {
    return stream << rhs.value;
  }

};

template <class T, std::size_t N>
class factorials {
public:
  using value_type = T;
  static constexpr std::size_t size = N;

public:
  std::array<value_type, size + 1> fact{};
  std::array<value_type, size + 1> fact_inv{};

  factorials() {
    fact.front() = value_type(1);
    for (std::size_t i = 1; i <= size; ++i) {
      fact[i] = fact[i - 1] * value_type(i);
    }
    fact_inv.back() = ~fact.back();
    for (std::size_t i = size; i > 0; --i) {
      fact_inv[i - 1] = fact_inv[i] * value_type(i);
    }
  }

  value_type operator () (std::size_t n, std::size_t r) const {
    return fact[n] * fact_inv[n - r] * fact_inv[r];
  }

};

using modint = modular<998244353>;
factorials<modint, 1500000> fact;

modint calc(int n, int k) {
  if (n < 0 || k <= 0) {
    return modint(0);
  }
  return fact(n + k - 1, n);
}

int main() {
  int N, M;
  std::cin >> N >> M;
  modint ans;
  for (int odd: range(0, std::min(N, M) + 1)) {
    int sum = 3 * M - odd;
    if (sum % 2 != 0) {
      continue;
    }
    modint all;
    all += calc(sum / 2, N);
    all -= calc(sum / 2 - M, N) * modint(odd);
    all -= calc(sum / 2 - M - 1, N) * modint(N - odd);
    ans += all * fact(N, odd);
  }
  std::cout << ans << '\n';
  return 0;
}


Compiler output:
a.cc:57:11: error: 'uint32_t' has not been declared
   57 | template <uint32_t Modulus>
      |           ^~~~~~~~
a.cc:60:22: error: 'uint32_t' does not name a type
   60 |   using value_type = uint32_t;
      |                      ^~~~~~~~
a.cc:8:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    7 | #include <array>
  +++ |+#include <cstdint>
    8 | 
a.cc:61:20: error: 'uint64_t' does not name a type
   61 |   using max_type = uint64_t;
      |                    ^~~~~~~~
a.cc:61:20: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:63:20: error: 'value_type' does not name a type
   63 |   static constexpr value_type mod = Modulus;
      |                    ^~~~~~~~~~
a.cc:64:20: error: 'value_type' does not name a type
   64 |   static constexpr value_type mod_min = 1;
      |                    ^~~~~~~~~~
a.cc:65:20: error: 'value_type' does not name a type
   65 |   static constexpr value_type mod_max = 2147483647;
      |                    ^~~~~~~~~~
a.cc:66:17: error: 'mod' was not declared in this scope
   66 |   static_assert(mod >= mod_min, "invalid mod :: too small");
      |                 ^~~
a.cc:66:24: error: 'mod_min' was not declared in this scope
   66 |   static_assert(mod >= mod_min, "invalid mod :: too small");
      |                        ^~~~~~~
a.cc:67:17: error: 'mod' was not declared in this scope
   67 |   static_assert(mod <= mod_max, "invalid mod :: too big");
      |                 ^~~
a.cc:67:24: error: 'mod_max' was not declared in this scope
   67 |   static_assert(mod <= mod_max, "invalid mod :: too big");
      |                        ^~~~~~~
a.cc:70:20: error: 'value_type' does not name a type
   70 |   static constexpr value_type normalize(T value_) {
      |                    ^~~~~~~~~~
a.cc:81:3: error: 'value_type' does not name a type
   81 |   value_type value;
      |   ^~~~~~~~~~
a.cc:90:13: error: 'value_type' does not name a type
   90 |   constexpr value_type operator () () const { return value; }
      |             ^~~~~~~~~~
a.cc:94:13: error: 'value_type' does not name a type
   94 |   constexpr value_type &extract() { return value; }
      |             ^~~~~~~~~~
a.cc:96:27: error: 'max_type' has not been declared
   96 |   constexpr modular power(max_type exp) const {
      |                           ^~~~~~~~
a.cc:164:12: error: 'modint' was not declared in this scope; did you mean 'mode_t'?
  164 | factorials<modint, 1500000> fact;
      |            ^~~~~~
      |            mode_t
a.cc:164:27: error: template argument 1 is invalid
  164 | factorials<modint, 1500000> fact;
      |                           ^
a.cc:166:1: error: 'modint' does not name a type; did you mean 'mode_t'?
  166 | modint calc(int n, int k) {
      | ^~~~~~
      | mode_t
a.cc: In function 'int main()':
a.cc:176:3: error: 'modint' was not declared in this scope; did you mean 'mode_t'?
  176 |   modint ans;
      |   ^~~~~~
      |   mode_t
a.cc:182:11: error: expected ';' before 'all'
  182 |     modint all;
      |           ^~~~
      |           ;
a.cc:183:5: error: 'all' was not declared in this scope; did you mean 'atoll'?
  183 |     all += calc(sum / 2, N);
      |     ^~~
      |     atoll
a.cc:183:12: error: 'calc' was not declared in this scope; did you mean 'calloc'?
  183 |     all += calc(sum / 2, N);
      |            ^~~~
      |            calloc
a.cc:186:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
  186 |     ans += all * fact(N, odd);
      |     ^~~
      |     abs
a.cc:186:22: error: 'fact' cannot be used as a function
  186 |     ans += all * fact(N, odd);
      |                  ~~~~^~~~~~~~
a.cc:188:16: error: 'ans' was not declared in this scope; did you mean 'abs'?
  188 |   std::cout << ans << '\n';
      |                ^~~
      |                abs