結果

問題 No.1186 長方形の敷き詰め
ユーザー risujirohrisujiroh
提出日時 2020-08-22 13:10:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,957 bytes
コンパイル時間 4,375 ms
コンパイル使用メモリ 259,540 KB
実行使用メモリ 14,916 KB
最終ジャッジ日時 2023-08-05 09:57:24
合計ジャッジ時間 3,939 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 19 ms
14,592 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 24 ms
14,916 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 8 ms
6,636 KB
testcase_18 AC 13 ms
10,564 KB
testcase_19 AC 14 ms
12,080 KB
testcase_20 AC 17 ms
13,176 KB
testcase_21 AC 13 ms
10,008 KB
testcase_22 AC 20 ms
14,636 KB
testcase_23 AC 12 ms
9,516 KB
testcase_24 AC 17 ms
13,172 KB
testcase_25 AC 11 ms
9,440 KB
testcase_26 AC 14 ms
10,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

template <class T, class Op = multiplies<>>
constexpr T power(T a, uint64_t n, T init = 1, Op op = Op{}) {
  while (n) {
    if (n & 1) init = op(init, a);
    if (n >>= 1) a = op(a, a);
  }
  return init;
}

template <uint32_t M>
struct modular {
  using T = modular;
  static constexpr uint32_t mod = M;
  uint32_t v;
  modular(int64_t x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  T operator-() const { return T() -= *this; }
  T& operator+=(T b) { return (int)(v += b.v - mod) < 0 ? v += mod : v, *this; }
  T& operator-=(T b) { return (int)(v -= b.v) < 0 ? v += mod : v, *this; }
  T& operator*=(T b) { return v = (uint64_t)v * b.v % mod, *this; }
  T& operator/=(T b) { return *this *= power(b, mod - 2); }
  friend T operator+(T a, T b) { return a += b; }
  friend T operator-(T a, T b) { return a -= b; }
  friend T operator*(T a, T b) { return a *= b; }
  friend T operator/(T a, T b) { return a /= b; }
  friend bool operator==(T a, T b) { return a.v == b.v; }
};

using mint = modular<998244353>;

vector<mint> fact, inv_fact, minv;
void prepare(int n) {
  fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
  for (int i = 0; i <= n; ++i) fact[i] = i ? fact[i - 1] * i : 1;
  inv_fact[n] = power(fact[n], mint::mod - 2);
  for (int i = n; i--;) inv_fact[i] = (i + 1) * inv_fact[i + 1];
  for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}
mint binom(int n, int k) {
  if (k < 0 or k > n) return 0;
  return fact[n] * inv_fact[k] * inv_fact[n - k];
}
template <>
mint& mint::operator/=(mint b) {
  return *this *= b.v < minv.size() ? minv[b.v] : power(b, mod - 2);
}

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  prepare(m);
  mint res;
  for (int x = 0; n * x <= m; ++x) {
    int y = m - n * x;
    res += binom(x + y, x);
  }
  if (n == 1) res = 1;
  cout << res.v << '\n';
}
0