結果

問題 No.2023 Tiling is Fun
ユーザー tnakao0123tnakao0123
提出日時 2022-07-31 02:33:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,584 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 42,696 KB
実行使用メモリ 4,612 KB
最終ジャッジ日時 2023-09-28 03:59:21
合計ジャッジ時間 1,930 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,472 KB
testcase_01 AC 23 ms
4,608 KB
testcase_02 AC 13 ms
4,468 KB
testcase_03 AC 13 ms
4,580 KB
testcase_04 AC 3 ms
4,464 KB
testcase_05 AC 12 ms
4,580 KB
testcase_06 AC 14 ms
4,604 KB
testcase_07 AC 25 ms
4,596 KB
testcase_08 AC 17 ms
4,576 KB
testcase_09 AC 22 ms
4,568 KB
testcase_10 AC 22 ms
4,536 KB
testcase_11 AC 2 ms
4,584 KB
testcase_12 AC 3 ms
4,468 KB
testcase_13 AC 3 ms
4,588 KB
testcase_14 AC 19 ms
4,528 KB
testcase_15 AC 17 ms
4,544 KB
testcase_16 AC 18 ms
4,612 KB
testcase_17 AC 34 ms
4,472 KB
testcase_18 AC 35 ms
4,492 KB
testcase_19 AC 25 ms
4,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2023.cc:  No.2023 Tiling is Fun - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) {}
  MI(long long _v): v(_v % MOD) {}

  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

typedef MI<MOD> mi;

/* global variables */

mi fs[MAX_N + 1], invfs[MAX_N + 1];

/* subroutines */

inline mi nck(int n, int k) {  // nCk % MOD
  if (n < k || k < 0) return 0;
  return fs[n] * invfs[n - k] * invfs[k];
}

void prepare_fracs(int n) {
  fs[0] = invfs[0] = 1;
  for (int i = 1; i <= n; i++) {
    fs[i] = fs[i - 1] * i;
    invfs[i] = fs[i].inv();
  }
}

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  a--, b--;

  int n = a + b;
  prepare_fracs(n);

  printf("%d\n", nck(n, a).v);
  return 0;
}
0