結果

問題 No.802 だいたい等差数列
ユーザー ats5515ats5515
提出日時 2019-03-17 22:55:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 2,028 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 77,776 KB
実行使用メモリ 34,880 KB
最終ジャッジ日時 2023-09-22 09:15:05
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
34,744 KB
testcase_01 AC 35 ms
34,856 KB
testcase_02 AC 35 ms
34,664 KB
testcase_03 AC 35 ms
34,644 KB
testcase_04 AC 35 ms
34,596 KB
testcase_05 AC 35 ms
34,648 KB
testcase_06 AC 34 ms
34,648 KB
testcase_07 AC 35 ms
34,592 KB
testcase_08 AC 35 ms
34,592 KB
testcase_09 AC 35 ms
34,876 KB
testcase_10 AC 35 ms
34,656 KB
testcase_11 AC 35 ms
34,744 KB
testcase_12 AC 35 ms
34,816 KB
testcase_13 AC 35 ms
34,656 KB
testcase_14 AC 36 ms
34,668 KB
testcase_15 AC 37 ms
34,660 KB
testcase_16 AC 36 ms
34,640 KB
testcase_17 AC 35 ms
34,592 KB
testcase_18 AC 35 ms
34,860 KB
testcase_19 AC 37 ms
34,640 KB
testcase_20 AC 41 ms
34,880 KB
testcase_21 AC 42 ms
34,596 KB
testcase_22 AC 35 ms
34,720 KB
testcase_23 AC 37 ms
34,592 KB
testcase_24 AC 34 ms
34,604 KB
testcase_25 AC 35 ms
34,576 KB
testcase_26 AC 35 ms
34,604 KB
testcase_27 AC 34 ms
34,600 KB
testcase_28 AC 37 ms
34,736 KB
testcase_29 AC 41 ms
34,656 KB
testcase_30 AC 35 ms
34,672 KB
testcase_31 AC 34 ms
34,580 KB
testcase_32 AC 35 ms
34,600 KB
testcase_33 AC 35 ms
34,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};

using comb = comb_util<long long, 1000000007, 2000100>;
comb cb;
inline int add(int u, int v) {
	u += v;
	if (u >= MOD) u -= MOD;
	return u;
}

inline int sub(int u, int v) {
	u -= v;
	if (u < 0) u += MOD;
	return u;
}

inline int mul(int u, int v) {
	return (long long)u * v % MOD;
}
//0<=Ai<lim, SUM(Ai)=sum
int solve(int n, int sum, int lim) {
	if (n == 0) {
		if (sum == 0) return 1;
		else return 0;
	}
	int res = 0;


	for (int i = 0; i <= n - 2; i++) {
		int sumNow = sum - lim * i;
		if (sumNow < 0) break;
		int foo = cb.binom(n-2, i);
		foo = mul(foo, cb.binom(sumNow + n - 1, n - 1));
		if (i & 1) {
			res = sub(res, foo);
		}
		else {
			res = add(res, foo);
		}
	}

	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, D1, D2;
	cin >> N >> M >> D1 >> D2;
	int res = solve(N + 1, M - (N - 1) * D1 - 1, D2 - D1 + 1);




	cout << res << endl;
}
0