結果
| 問題 |
No.2141 Enumeratest
|
| コンテスト | |
| ユーザー |
Kome_soudou
|
| 提出日時 | 2022-12-02 21:37:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,256 bytes |
| コンパイル時間 | 1,562 ms |
| コンパイル使用メモリ | 170,532 KB |
| 実行使用メモリ | 18,900 KB |
| 最終ジャッジ日時 | 2024-10-09 22:44:49 |
| 合計ジャッジ時間 | 7,736 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 RE * 18 |
ソースコード
#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;
}
Kome_soudou