結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー square1001square1001
提出日時 2020-08-22 13:27:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,994 bytes
コンパイル時間 922 ms
コンパイル使用メモリ 77,828 KB
実行使用メモリ 11,324 KB
最終ジャッジ日時 2024-04-23 07:54:36
合計ジャッジ時間 2,059 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
11,220 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 15 ms
11,056 KB
testcase_16 AC 15 ms
11,216 KB
testcase_17 AC 15 ms
11,216 KB
testcase_18 AC 16 ms
11,000 KB
testcase_19 AC 16 ms
11,124 KB
testcase_20 AC 15 ms
11,152 KB
testcase_21 AC 15 ms
11,012 KB
testcase_22 AC 15 ms
11,056 KB
testcase_23 AC 15 ms
11,060 KB
testcase_24 AC 15 ms
11,052 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template <std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int lim = 1000000;
using mint = modint<998244353>;
int main() {
	vector<mint> fact(lim + 1), factinv(lim + 1);
	fact[0] = 1; 
	for (int i = 1; i <= lim; ++i) fact[i] = fact[i - 1] * i;
	factinv[lim] = fact[lim].inv();
	for (int i = lim; i >= 1; --i) factinv[i - 1] = factinv[i] * i;
	function<mint(int, int)> comb = [&](int x, int y) {
		if (x < y || y < 0) return mint(0);
		return fact[x] * factinv[y] * factinv[x - y];
	};
	int N, M, A, B;
	cin >> N >> M >> A >> B;
	mint ans = 0;
	for (long long i = 1LL * A * (N - 1); i <= B && i < M; ++i) {
		int frees = i - 1LL * A * (N - 1);
		ans += comb(frees + N - 1, frees) * (M - i);
	}
	ans *= fact[N];
	cout << ans.get() << endl;
	return 0;
}
0