結果

問題 No.802 だいたい等差数列
ユーザー heno239heno239
提出日時 2019-03-10 00:35:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,174 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 108,576 KB
実行使用メモリ 19,240 KB
最終ジャッジ日時 2023-09-14 12:06:59
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
18,960 KB
testcase_01 AC 17 ms
18,960 KB
testcase_02 AC 18 ms
18,972 KB
testcase_03 AC 17 ms
18,952 KB
testcase_04 AC 17 ms
18,964 KB
testcase_05 AC 17 ms
18,972 KB
testcase_06 AC 18 ms
18,980 KB
testcase_07 AC 17 ms
19,088 KB
testcase_08 AC 17 ms
18,988 KB
testcase_09 AC 17 ms
18,988 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 19 ms
19,044 KB
testcase_13 RE -
testcase_14 AC 20 ms
18,960 KB
testcase_15 AC 18 ms
18,988 KB
testcase_16 AC 20 ms
18,964 KB
testcase_17 AC 19 ms
19,024 KB
testcase_18 AC 19 ms
19,080 KB
testcase_19 AC 19 ms
18,964 KB
testcase_20 AC 20 ms
19,100 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 19 ms
18,960 KB
testcase_24 AC 19 ms
19,008 KB
testcase_25 AC 17 ms
19,020 KB
testcase_26 AC 19 ms
19,240 KB
testcase_27 AC 19 ms
18,952 KB
testcase_28 AC 19 ms
18,960 KB
testcase_29 RE -
testcase_30 AC 17 ms
18,972 KB
testcase_31 AC 17 ms
18,960 KB
testcase_32 AC 17 ms
19,020 KB
testcase_33 AC 17 ms
19,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
ll mod_inverse(ll a) {
	ll n = mod - 2;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%mod;
		a = a * a%mod; n >>= 1;
	}
	return res;
}
const int N_MAX = 1000001;
ll p[N_MAX], invp[N_MAX];
void init() {
	p[0] = 1;
	rep1(i, N_MAX - 1) {
		p[i] = p[i - 1] * i%mod;
	}
	invp[N_MAX - 1] = mod_inverse(p[N_MAX - 1]);
	per(i, N_MAX - 1) {
		invp[i] = invp[i + 1] * (i + 1) % mod;
	}
}
//xCyを求める
ll comb(ll x, ll y) {
	if (x < y || y<0)return 0;
	ll res = p[x];
	(res *= invp[y]) %= mod;
	(res *= invp[x - y]) %= mod;
	return res;
}
//xPyを求める
ll comb2(ll x, ll y) {
	return p[x] * invp[x - y] % mod;
}
int main() {
	init();
	ll n, m; cin >> n >> m;
	ll d1, d2; cin >> d1 >> d2;
	//左端を消し、a1<a2<...<anにする
	//このとき差は1以上d2-d1+1以下になる
	m -= (d1-1)*(n - 1);
	d2 -= d1-1;

	ll ans = 0;
	//条件を満たさないやつをi個として、包除原理
	rep(i, n) {
		//差がd2+1以上のやつは先にd2引いておいて残りをn-1個に再分配すると考えて問題ない
		ll rest = m - d2 * i;

		//一般に、1<=a1<a2<...<an<=mを満たす数列aの個数はmCn
		ll csum = comb(rest, n)*comb(n - 1, i)%mod;
		if (i % 2)ans += mod-csum;
		else ans += csum;
	}
	cout << ans % mod << endl;
	//stop
	return 0;
}
0