結果

問題 No.2141 Enumeratest
ユーザー Kome_soudouKome_soudou
提出日時 2022-12-02 21:37:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,256 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 167,964 KB
実行使用メモリ 18,880 KB
最終ジャッジ日時 2024-04-18 05:23:50
合計ジャッジ時間 7,454 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
10,992 KB
testcase_01 AC 22 ms
11,004 KB
testcase_02 AC 62 ms
13,036 KB
testcase_03 AC 24 ms
18,836 KB
testcase_04 AC 1,304 ms
18,880 KB
testcase_05 RE -
testcase_06 AC 21 ms
10,988 KB
testcase_07 AC 22 ms
11,736 KB
testcase_08 AC 24 ms
13,780 KB
testcase_09 AC 24 ms
12,796 KB
testcase_10 AC 24 ms
15,448 KB
testcase_11 AC 25 ms
18,148 KB
testcase_12 AC 22 ms
11,328 KB
testcase_13 AC 22 ms
12,676 KB
testcase_14 AC 26 ms
18,132 KB
testcase_15 AC 26 ms
15,228 KB
testcase_16 AC 25 ms
16,100 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 279 ms
18,404 KB
testcase_25 AC 35 ms
13,652 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 732 ms
17,048 KB
testcase_35 RE -
testcase_36 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// a^b mod p
int64_t ModPow(int64_t a, int64_t b, int64_t p)
{
	int64_t ans = 1;
	while(b > 0)
	{
		if(b & 1) ans = (ans * a) % p; // bの最下位bitが1ならa^(2^i)をかける
		a = (a * a) % p;
		b >>= 1; // bを1bit右にシフト
	}
	return ans;
}
vector<int64_t> fact; // 階乗の値
// i! mod p (0<=i<=n)の計算結果を配列に記録
void Factorial(int64_t n, int64_t p)
{
	fact.resize(n + 1);
	fact.at(0) = 1;
	if(n > 0) fact.at(1) = 1;
	for(int64_t i = 2; i <= n; i++) fact.at(i) = (fact.at(i - 1) * i) % p;
	return;
}
// nCk mod p
int64_t ModComb(int64_t n, int64_t k, int64_t p)
{
	int64_t ans = fact.at(n);
	ans *= ModPow(fact.at(k), p - 2, p);
	ans %= p;
	ans *= ModPow(fact.at(n - k), p - 2, p);
	ans %= p;
	return ans;
}

int main()
{
	int64_t n, m;
	cin >> n >> m;
	const int64_t mod = 998244353;
	
	vector<int64_t> b(m);
	int64_t cnt = m;
	for(int64_t i = 0; i < n; i++)
	{
		b[i] += m / n;
		cnt -= m / n;
	}
	for(int64_t i = 0; i < n; i++)
	{
		if(cnt == 0) break;
		b[i]++;
		cnt--;
	}
	
	Factorial(1000001, mod);
	int64_t ans = 1;
	int64_t nb = m;
	for(int64_t i = 0; i < n; i++)
	{
		ans *= ModComb(nb, b[i], mod);
		ans %= mod;
		nb -= b[i];
	}
	cout << ans << endl;
	return 0;
}
0