結果

問題 No.802 だいたい等差数列
ユーザー yurujirouyurujirou
提出日時 2021-09-26 16:10:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 514 ms / 2,000 ms
コード長 1,561 bytes
コンパイル時間 3,340 ms
コンパイル使用メモリ 173,092 KB
実行使用メモリ 34,948 KB
最終ジャッジ日時 2023-09-19 02:54:57
合計ジャッジ時間 21,228 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 463 ms
34,688 KB
testcase_01 AC 465 ms
34,668 KB
testcase_02 AC 465 ms
34,612 KB
testcase_03 AC 466 ms
34,692 KB
testcase_04 AC 465 ms
34,748 KB
testcase_05 AC 467 ms
34,648 KB
testcase_06 AC 465 ms
34,896 KB
testcase_07 AC 465 ms
34,948 KB
testcase_08 AC 465 ms
34,684 KB
testcase_09 AC 466 ms
34,868 KB
testcase_10 AC 466 ms
34,644 KB
testcase_11 AC 468 ms
34,608 KB
testcase_12 AC 469 ms
34,644 KB
testcase_13 AC 468 ms
34,748 KB
testcase_14 AC 467 ms
34,700 KB
testcase_15 AC 467 ms
34,644 KB
testcase_16 AC 469 ms
34,864 KB
testcase_17 AC 468 ms
34,732 KB
testcase_18 AC 468 ms
34,676 KB
testcase_19 AC 469 ms
34,668 KB
testcase_20 AC 472 ms
34,756 KB
testcase_21 AC 470 ms
34,672 KB
testcase_22 AC 471 ms
34,596 KB
testcase_23 AC 469 ms
34,756 KB
testcase_24 AC 467 ms
34,596 KB
testcase_25 AC 465 ms
34,692 KB
testcase_26 AC 467 ms
34,604 KB
testcase_27 AC 514 ms
34,696 KB
testcase_28 AC 468 ms
34,600 KB
testcase_29 AC 469 ms
34,616 KB
testcase_30 AC 466 ms
34,812 KB
testcase_31 AC 470 ms
34,608 KB
testcase_32 AC 467 ms
34,676 KB
testcase_33 AC 469 ms
34,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <deque>
#include <functional>
#include <math.h>
#include <complex>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define RREP(i,n) for(int i = (int)n-1; i >= 0; i--)
#define LREP(i,n) for(LL i = 0; i < (LL)n; i++)

#define Vi vector<int>
#define Vl vector<long long>
#define LP pair<long long ,long long>
#define P pair<int, int>
#define T3 tuple<LL, LL, LL>
#define T4 tuple<LL, LL, LL, LL>
#define INF 1000000007
#define SIZE	2000010
#define MOD 1000000007
typedef long long LL;

LL F[SIZE], FI[SIZE];
void init() {
	F[0] = FI[0] = 1;
	for (LL i = 1; i < SIZE; i++) {
		F[i] = (F[i - 1] * i) % MOD;
		FI[i] = (FI[i - 1] * inv_mod(i, MOD)) % MOD;
	}
}

LL comb(LL n, LL k) {
	if (n < k) return 0;
	LL res = F[n];
	res = (res * FI[n - k]) % MOD;
	res = (res * FI[k]) % MOD;
	return res;
}

LL N, M, D1, D2;

LL cal(LL x) {
	LL n = (M - 1) - (N - 1) * D1;
	n -= x * (D2 - D1 + 1);
	LL res = comb(n + N, N);
	res = (res * comb(N - 1, x)) % MOD;
	return res;
}

int main() {
	cin >> N >> M >> D1 >> D2;
	init();

	LL ans = 0;
	for (LL x = 1; x <= N - 1; x++) {
		LL res = cal(x);
		if (x % 2 == 1) {
			ans = (ans + res) % MOD;
		}
		else {
			ans = (ans - res) % MOD;
		}
	}
	ans = (cal(0) - ans) % MOD;
	cout << (ans + MOD) % MOD << endl;
}
0