結果
| 問題 | No.2141 Enumeratest |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-25 08:18:39 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| + 272µs | |
| コード長 | 1,853 bytes |
| 記録 | |
| コンパイル時間 | 4,122 ms |
| コンパイル使用メモリ | 376,184 KB |
| 実行使用メモリ | 18,944 KB |
| 最終ジャッジ日時 | 2026-07-25 08:18:46 |
| 合計ジャッジ時間 | 5,929 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
constexpr int mod = 998244353;
long long power_mod(long long a, long long p) {
if (p==0) return 1LL;
a %= mod;
if (a<0) a += mod;
if (p<0) {
assert(gcd(a,mod)==1);
p = (p%(mod-1))+mod-1;
}
long long result = 1;
long long b = a;
while (p>0) {
if (p&1LL) result = result*b%mod;
b = b*b%mod;
p >>= 1;
}
return result;
}
vector<long long> factorial;
vector<long long> fact_inv;
void make_factorial(int n, bool make_inv = true) {
assert(n>=0);
if (make_inv) assert(n<mod);
factorial.assign(n+1,1);
for (int i=1; i<=n; i++) {
factorial[i] = factorial[i-1]*i%mod;
}
if (!make_inv) return;
fact_inv.assign(n+1,power_mod(factorial[n],-1));
for (int i=n; i>0; i--) {
fact_inv[i-1] = fact_inv[i]*i%mod;
}
}
long long comb(int n, int r) {
if (r<0) return 0;
if (r>n) return 0;
long long result = factorial[n];
result *= fact_inv[r];
result %= mod;
result *= fact_inv[n-r];
result %= mod;
return result;
}
long long comb_inv(int n, int r) {
assert(r>=0);
assert(r<=n);
assert(n<mod);
long long result = fact_inv[n];
result *= factorial[r];
result %= mod;
result *= factorial[n-r];
result %= mod;
return result;
}
/////////////////// メイン ///////////////////
int main () {
//////////////////// 入力 ////////////////////
int n, m;
cin >> n >> m;
//////////////// 出力変数定義 ////////////////
long long result = 1;
//////////////////// 処理 ////////////////////
make_factorial(m);
while (n>0) {
int k = m/n;
result *= comb(m,k);
result %= mod;
m -= k;
n--;
}
//////////////////// 出力 ////////////////////
cout << result << endl;
//////////////////// 終了 ////////////////////
return 0;
}