結果
| 問題 |
No.1191 数え上げを愛したい(数列編)
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2020-08-22 14:56:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 2,069 bytes |
| コンパイル時間 | 6,555 ms |
| コンパイル使用メモリ | 249,244 KB |
| 最終ジャッジ日時 | 2025-01-13 09:01:12 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#include <bits/extc++.h>
#ifndef DUMP
#define DUMP(...) (void)0
#endif
using namespace std;
template <class T, class Op = multiplies<>>
constexpr T power(T a, uint64_t n, T init = 1, Op op = Op{}) {
while (n) {
if (n & 1) init = op(init, a);
if (n >>= 1) a = op(a, a);
}
return init;
}
template <uint32_t M>
struct modular {
using T = modular;
static constexpr uint32_t mod = M;
uint32_t v;
modular(int64_t x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
T operator-() const { return T() -= *this; }
T& operator+=(T b) { return (int)(v += b.v - mod) < 0 ? v += mod : v, *this; }
T& operator-=(T b) { return (int)(v -= b.v) < 0 ? v += mod : v, *this; }
T& operator*=(T b) { return v = (uint64_t)v * b.v % mod, *this; }
T& operator/=(T b) { return *this *= power(b, mod - 2); }
friend T operator+(T a, T b) { return a += b; }
friend T operator-(T a, T b) { return a -= b; }
friend T operator*(T a, T b) { return a *= b; }
friend T operator/(T a, T b) { return a /= b; }
friend bool operator==(T a, T b) { return a.v == b.v; }
};
using mint = modular<998244353>;
vector<mint> fact, inv_fact, minv;
void prepare(int n) {
fact.resize(n + 1), inv_fact.resize(n + 1), minv.resize(n + 1);
for (int i = 0; i <= n; ++i) fact[i] = i ? fact[i - 1] * i : 1;
inv_fact[n] = power(fact[n], mint::mod - 2);
for (int i = n; i--;) inv_fact[i] = (i + 1) * inv_fact[i + 1];
for (int i = 1; i <= n; ++i) minv[i] = inv_fact[i] * fact[i - 1];
}
mint binom(int64_t n, int64_t k) {
if (k < 0 or k > n) return 0;
return fact[n] * inv_fact[k] * inv_fact[n - k];
}
template <>
mint& mint::operator/=(mint b) {
return *this *= b.v < minv.size() ? minv[b.v] : power(b, mod - 2);
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int64_t n, m, a, b;
cin >> n >> m >> a >> b;
prepare(n + m);
mint res;
for (int i = 1; i <= m; ++i) {
res += binom(min(m - i, b) - (n - 1) * (a - 1), n - 1);
}
DUMP(res);
res *= fact[n];
cout << res.v << '\n';
}
risujiroh