結果

問題 No.2409 Strange Werewolves
ユーザー Today03Today03
提出日時 2023-08-11 21:54:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 4,472 ms
コンパイル使用メモリ 264,128 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-04-29 12:48:57
合計ジャッジ時間 5,934 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 87 ms
7,936 KB
testcase_04 AC 87 ms
8,064 KB
testcase_05 AC 44 ms
5,632 KB
testcase_06 AC 87 ms
7,936 KB
testcase_07 AC 87 ms
7,808 KB
testcase_08 AC 48 ms
5,760 KB
testcase_09 AC 52 ms
6,016 KB
testcase_10 AC 26 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 27 ms
5,376 KB
testcase_13 AC 47 ms
5,760 KB
testcase_14 AC 56 ms
6,144 KB
testcase_15 AC 52 ms
6,016 KB
testcase_16 AC 41 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <typename mint>
struct combination {
  vector<mint> fact,factinv;

  combination(int n) {
    fact.resize(n+1);
    factinv.resize(n+1);
    fact[0]=1;
    for (int i=1;i<=n;i++) {
      fact[i]=fact[i-1]*i;
    }
    for (int i=0;i<=n;i++) {
      factinv[i]=fact[i].inv();
    }
  }

  mint nCr(long long n,long long r) {
    if (n<0||r<0||n-r<0) {
      return 0;
    }
    return fact[n]*factinv[r]*factinv[n-r];
  }
  
  mint nPr(long long n,long long r) {
    if (n<0||r<0||n-r<0) {
      return 0;
    }
    return fact[n]*factinv[n-r];
  }
};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  using mint=modint998244353;
  int x,y,z,w;
  cin>>x>>y>>z>>w;
  combination<mint> c(x+y);
  cout<<(c.nCr(x,z)*c.nCr(y,w)*c.fact[x+y-z-w-1]*(z==0?x:y)).val()<<endl;
}
0