結果

問題 No.2409 Strange Werewolves
ユーザー atug tokyoatug tokyo
提出日時 2023-08-11 22:29:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 4,385 bytes
コンパイル時間 2,284 ms
コンパイル使用メモリ 206,548 KB
実行使用メモリ 10,104 KB
最終ジャッジ日時 2024-04-29 13:30:56
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 11 ms
7,936 KB
testcase_04 AC 16 ms
10,104 KB
testcase_05 AC 6 ms
5,504 KB
testcase_06 AC 12 ms
8,344 KB
testcase_07 AC 13 ms
9,088 KB
testcase_08 AC 7 ms
5,760 KB
testcase_09 AC 10 ms
7,040 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 8 ms
6,144 KB
testcase_14 AC 9 ms
6,400 KB
testcase_15 AC 8 ms
6,016 KB
testcase_16 AC 8 ms
6,272 KB
testcase_17 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>

using namespace std;
using ll = long long;
using ld = long double;
using mint = atcoder::modint998244353;
using Pair = pair<int, int>;
using Tuple = tuple<int, int, int>;
using VI1 = vector<int>;
using VI2 = vector<VI1>;
using VL1 = vector<ll>;
using VL2 = vector<VL1>;
using VD1 = vector<ld>;
using VD2 = vector<VD1>;
using VB1 = vector<bool>;
using VB2 = vector<VB1>;
using VP1 = vector<Pair>;
using VP2 = vector<VP1>;
using VT1 = vector<Tuple>;
using VT2 = vector<VT1>;
using VM1 = vector<mint>;
using VM2 = vector<VM1>;
using Queue = queue<int>;
using DQ = deque<int>;
using PQ = priority_queue<int, vector<int>, greater<int>>;
using Table = VI2;
using Graph = VI2;

/** io */
template <typename T>
std::vector<T> input_vec(int N);
template <typename T>
void output_row(std::vector<T> &row);
template <typename T>
void output_col(std::vector<T> &col);
void outputYesNo(bool yes, const string &Yes = "Yes", const string &No = "No");
/** minmax */
template <typename T>
bool chmin(T &a, T b);
template <typename T>
bool chmax(T &a, T b);

/**
 * 組み合わせと順列を計算するクラス
 *
 * @tparam T 組み合わせ・順列を計算する体 (field)
 *
 * T の例: atcoder::modint
 *
 * 参考文献
 * https://github.com/atcoder/live_library/blob/master/comb.cpp
 */
template <typename T>
struct modcombi {
  /** 組み合わせ・順列の引数の上限 */
  int sup;
  /** 階乗。factorial の略 */
  vector<T> fac;
  /** 階乗の逆元。inverse の略 */
  vector<T> inv;
  /**
   * コンストラクタ
   *
   * @param[in] sup 組み合わせ・順列の引数の上限
   *
   * 階乗と階乗の逆元の計算を行う。
   * 計算量 O(sup)
   */
  modcombi(int sup) : sup(sup) {
    assert(1 <= sup && sup <= int(1e+7));
    fac.resize(sup + 1);
    inv.resize(sup + 1);
    fac.at(0) = 1;
    for (int i = 0; i < sup; ++i) fac.at(i + 1) = fac.at(i) * (i + 1);
    inv.at(sup) = 1 / fac.at(sup);
    for (int i = sup; i > 0; --i) {
      inv.at(i - 1) = inv.at(i) * i;
      assert(fac.at(i) * inv.at(i) == 1);
    }
  }
  /**
   * コピーコンストラクタ
   *
   * 計算量 O(sup)
   */
  modcombi(const modcombi &org) : sup(org.sup), fac(org.fac), inv(org.inv) {}
  /**
   * 組み合わせ (combination) の計算
   *
   * @param[in] n nCk の n
   * @param[in] k nCk の k
   * @return nCk
   *
   * 計算量 O(1)
   */
  T combi(int n, int k) {
    if (n < 0 || sup < n) return 0;
    if (k < 0 || n < k) return 0;
    return fac.at(n) * inv.at(k) * inv.at(n - k);
  }
  /**
   * 順列 (permutation) の計算
   *
   * @param[in] n nPk の n
   * @param[in] k nPk の k
   * @return nPk
   *
   * 計算量 O(1)
   */
  T perm(int n, int k) {
    if (n < 0 || sup < n) return 0;
    if (k < 0 || n < k) return 0;
    return fac.at(n) * inv.at(n - k);
  }
};
using MC = modcombi<mint>;

auto solve() {
  int X, Y, Z, W;
  cin >> X >> Y >> Z >> W;
  MC mc(X + Y + Z + W);
  auto V = X + Y - Z - W - 1;
  if (Z == 0) {
    swap(X, Y);
    swap(Z, W);
  }
  mint cnt = mc.combi(V, Y - 1);
  cnt *= mc.perm(Y, Y);
  cnt *= mc.perm(X, X - Z);
  return cnt.val();
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while (t--) {
    auto result = solve();
    cout << result << '\n';
    // output_row(result);
    // output_col(result);
    // outputYesNo(result, "Yes", "No");
  }
}

/** @note 使用頻度が高く毎回貼付するのが面倒なライブラリを実装しておく。*/

template <typename T>
std::vector<T> input_vec(int N) {
  std::vector<T> v(N);
  for (auto &vi : v) {
    cin >> vi;
  }
  return v;
}

void outputYesNo(bool yes, const string &Yes, const string &No) {
  if (yes)
    cout << Yes << '\n';
  else
    cout << No << '\n';
}

template <typename T>
void output_row(std::vector<T> &row) {
  int N = row.size();
  for (int i = 0; i < N; ++i) {
    if (i > 0) cout << ' ';
    cout << row.at(i);
  }
  cout << '\n';
}

template <typename T>
void output_col(std::vector<T> &col) {
  int N = col.size();
  for (int i = 0; i < N; ++i) {
    cout << col.at(i) << '\n';
  }
}

template <typename T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
0