結果

問題 No.2409 Strange Werewolves
ユーザー kotatsugamekotatsugame
提出日時 2023-08-11 21:28:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 75,692 KB
実行使用メモリ 8,984 KB
最終ジャッジ日時 2024-04-29 12:17:28
合計ジャッジ時間 1,444 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 11 ms
7,936 KB
testcase_04 AC 13 ms
8,984 KB
testcase_05 AC 13 ms
8,984 KB
testcase_06 AC 9 ms
7,296 KB
testcase_07 AC 8 ms
6,656 KB
testcase_08 AC 7 ms
5,632 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 7 ms
5,760 KB
testcase_15 AC 7 ms
5,888 KB
testcase_16 AC 8 ms
6,188 KB
testcase_17 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cassert>
#include<atcoder/modint>
using namespace std;
#include<vector>
template<typename T>
struct combination{
	vector<T>fac,ifac;
	combination(size_t N=0):fac(1,1),ifac(1,1)
	{
		make_table(N);
	}
	void make_table(size_t N)
	{
		if(fac.size()>N)return;
		size_t now=fac.size();
		N=max(N,now*2);
		fac.resize(N+1);
		ifac.resize(N+1);
		for(size_t i=now;i<=N;i++)fac[i]=fac[i-1]*i;
		ifac[N]=1/fac[N];
		for(size_t i=N;i-->now;)ifac[i]=ifac[i+1]*(i+1);
	}
	T factorial(size_t n)
	{
		make_table(n);
		return fac[n];
	}
	T invfac(size_t n)
	{
		make_table(n);
		return ifac[n];
	}
	T P(size_t n,size_t k)
	{
		if(n<k)return 0;
		make_table(n);
		return fac[n]*ifac[n-k];
	}
	T C(size_t n,size_t k)
	{
		if(n<k)return 0;
		make_table(n);
		return fac[n]*ifac[n-k]*ifac[k];
	}
	T H(size_t n,size_t k)
	{
		if(n==0)return k==0?1:0;
		return C(n-1+k,k);
	}
};
using mint=atcoder::modint998244353;
combination<mint>C;
int X,Y,Z,W;
mint f(int X,int Y,int W)
{
	return C.factorial(X)*C.P(Y,Y-W)*C.C(X-1+Y-W,X-1);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>X>>Y>>Z>>W;
	cout<<(Z==0?f(X,Y,W):f(Y,X,Z)).val()<<endl;
}
0