結果

問題 No.802 だいたい等差数列
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-18 22:08:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,624 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 64,632 KB
実行使用メモリ 34,868 KB
最終ジャッジ日時 2023-09-26 11:43:29
合計ジャッジ時間 58,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,600 ms
34,544 KB
testcase_01 AC 1,594 ms
34,620 KB
testcase_02 AC 1,600 ms
34,612 KB
testcase_03 AC 1,583 ms
34,648 KB
testcase_04 AC 1,602 ms
34,548 KB
testcase_05 AC 1,594 ms
34,544 KB
testcase_06 AC 1,597 ms
34,644 KB
testcase_07 AC 1,593 ms
34,548 KB
testcase_08 AC 1,606 ms
34,600 KB
testcase_09 AC 1,607 ms
34,608 KB
testcase_10 AC 1,590 ms
34,636 KB
testcase_11 AC 1,599 ms
34,728 KB
testcase_12 AC 1,604 ms
34,568 KB
testcase_13 AC 1,604 ms
34,608 KB
testcase_14 AC 1,600 ms
34,620 KB
testcase_15 AC 1,599 ms
34,540 KB
testcase_16 AC 1,624 ms
34,668 KB
testcase_17 AC 1,599 ms
34,612 KB
testcase_18 AC 1,612 ms
34,628 KB
testcase_19 AC 1,603 ms
34,672 KB
testcase_20 AC 1,617 ms
34,572 KB
testcase_21 AC 1,624 ms
34,776 KB
testcase_22 AC 1,604 ms
34,552 KB
testcase_23 AC 1,612 ms
34,612 KB
testcase_24 AC 1,607 ms
34,560 KB
testcase_25 AC 1,615 ms
34,608 KB
testcase_26 AC 1,616 ms
34,868 KB
testcase_27 AC 1,603 ms
34,612 KB
testcase_28 AC 1,597 ms
34,600 KB
testcase_29 AC 1,611 ms
34,624 KB
testcase_30 AC 1,583 ms
34,668 KB
testcase_31 AC 1,585 ms
34,780 KB
testcase_32 AC 1,589 ms
34,628 KB
testcase_33 AC 1,585 ms
34,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

typedef long long ll;

ll inf = 1e9+7;
ll func[2000010] = {0};
ll inv[2000010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			func[i] = 1;
			inv[i] = 1;
		}
		else{
			func[i] = (i*func[i-1])%inf;
			inv[i] = mult(func[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
    if(n<k) return 0;
	if(n<0 || k<0) return 1;
	else return (((func[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll hcomb(ll n,ll k){
	if(n==0 && k==0) return 1;
	return comb(n+k-1,k);
}

ll N,M,D1,D2;
int main(){
    cin >> N >> M >> D1 >> D2;
    factorial(2000000);
    ll ans = 0;
	ll x = M-1-D1*(N-1);
	if(x<0){
		cout << 0 << endl;
		return 0;
	}
    for(ll i=0;i<=N-1;i++){
		ll r = (comb(N-1,i)*comb(x-i*(D2-D1+1)+N,N))%inf;
        if(i%2==0) (ans += r)%=inf;
        else (ans += -r+inf)%=inf;
    }
    cout << ans << endl;
	return 0;
}
0