結果

問題 No.1191 数え上げを愛したい(数列編)
ユーザー akun0716akun0716
提出日時 2020-10-21 23:51:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 2,957 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 80,956 KB
最終ジャッジ日時 2023-09-28 14:29:56
合計ジャッジ時間 6,580 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
80,732 KB
testcase_01 AC 210 ms
80,668 KB
testcase_02 AC 201 ms
80,720 KB
testcase_03 AC 218 ms
80,956 KB
testcase_04 AC 199 ms
80,904 KB
testcase_05 AC 206 ms
80,724 KB
testcase_06 AC 203 ms
80,728 KB
testcase_07 AC 202 ms
80,672 KB
testcase_08 AC 200 ms
80,748 KB
testcase_09 AC 201 ms
80,800 KB
testcase_10 AC 212 ms
80,668 KB
testcase_11 AC 207 ms
80,788 KB
testcase_12 AC 192 ms
80,668 KB
testcase_13 AC 205 ms
80,672 KB
testcase_14 AC 207 ms
80,668 KB
testcase_15 AC 11 ms
11,576 KB
testcase_16 AC 11 ms
11,504 KB
testcase_17 AC 11 ms
11,560 KB
testcase_18 AC 10 ms
11,508 KB
testcase_19 AC 10 ms
11,596 KB
testcase_20 AC 11 ms
11,752 KB
testcase_21 AC 10 ms
11,552 KB
testcase_22 AC 200 ms
80,760 KB
testcase_23 AC 198 ms
80,852 KB
testcase_24 AC 11 ms
11,608 KB
testcase_25 AC 200 ms
80,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 998244353
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int modpow(int a, int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) {

		int halfP = p / 2;
		int half = modpow(a, halfP);

		return half * half % mod;
	}
	else {

		return a * modpow(a, p - 1) % mod;
	}
}

const long long MAX = 300010;  // 最大を決めておく
 // fac…階乗、inv…逆数、finv…逆数の累積積
long long fac[300010], finv[300010], inv[300010];

// テーブルを作る前処理、先にやっておく
void nPr_init() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
// nPrを計算する (前処理は忘れないように)
long long nPr(int n, int r) {
	if (n < 0 || r < 0 || n < r) return 0;
	return fac[n] * finv[n - r] % mod;
}

ll comb(ll N_, ll C_) {
	const int NUM_ = 3000001;
	static ll fact[3000002], factr[3000002], inv[3000002];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%mod, factr[i] = factr[i - 1] * inv[i] % mod;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % mod*factr[N_ - C_] % mod;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	nPr_init();
	//長さLの非負整数からなる数列で、
//合計がSになるものの個数は
//comb(S + L - 1, S);
	int N, M, A, B; cin >> N >> M >> A >> B;
	int ans = 0;
	/*
	if (A*(N - 1) <= B) {
		eFOR(i, A*(N - 1), B) {
			int tmp = comb(i + N - 2, i);
			tmp *= (M - i);
			ans += tmp;
			ans %= mod;
		}
	}
	*/
	eREP(i, B - A * (N - 1)) {
		int tmp = comb(i + N - 2, i);
		tmp *= (M - i - A * (N - 1));
		ans += tmp;
		ans %= mod;
	}
	cout << ans * fac[N] % mod << endl;
	return 0;
}

0