結果

問題 No.802 だいたい等差数列
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-18 22:07:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,018 bytes
コンパイル時間 710 ms
コンパイル使用メモリ 64,408 KB
実行使用メモリ 34,780 KB
最終ジャッジ日時 2023-09-26 11:39:14
合計ジャッジ時間 32,882 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,448 KB
testcase_01 AC 6 ms
5,500 KB
testcase_02 AC 7 ms
5,592 KB
testcase_03 AC 3 ms
5,348 KB
testcase_04 WA -
testcase_05 AC 9 ms
5,476 KB
testcase_06 AC 5 ms
5,476 KB
testcase_07 WA -
testcase_08 AC 6 ms
5,380 KB
testcase_09 AC 5 ms
5,508 KB
testcase_10 AC 1,456 ms
34,024 KB
testcase_11 AC 1,585 ms
34,332 KB
testcase_12 AC 1,413 ms
34,196 KB
testcase_13 AC 1,614 ms
34,692 KB
testcase_14 AC 1,459 ms
34,128 KB
testcase_15 AC 1,606 ms
34,468 KB
testcase_16 AC 1,528 ms
34,068 KB
testcase_17 AC 1,477 ms
34,176 KB
testcase_18 AC 1,602 ms
34,504 KB
testcase_19 AC 1,607 ms
34,628 KB
testcase_20 AC 1,625 ms
34,664 KB
testcase_21 AC 1,629 ms
34,548 KB
testcase_22 AC 1,614 ms
34,780 KB
testcase_23 AC 1,616 ms
34,680 KB
testcase_24 AC 1,602 ms
34,548 KB
testcase_25 AC 1,608 ms
34,592 KB
testcase_26 WA -
testcase_27 AC 1,604 ms
34,532 KB
testcase_28 WA -
testcase_29 AC 1,628 ms
34,652 KB
testcase_30 AC 2 ms
5,572 KB
testcase_31 AC 2 ms
5,412 KB
testcase_32 AC 2 ms
5,536 KB
testcase_33 AC 950 ms
25,876 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(2*M);
    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