結果

問題 No.802 だいたい等差数列
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-18 21:57:59
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 974 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 52,988 KB
実行使用メモリ 19,032 KB
最終ジャッジ日時 2023-09-26 10:42:46
合計ジャッジ時間 25,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 3 ms
5,356 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 5 ms
5,432 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 821 ms
19,032 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 798 ms
19,008 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 2 ms
5,424 KB
testcase_31 AC 2 ms
5,396 KB
testcase_32 WA -
testcase_33 AC 473 ms
17,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

typedef long long ll;

ll inf = 1e9+7;
ll func[1000010] = {0};
ll inv[1000010] = {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<=0 || k<0) return 0;
	if(k==0 || n==k) 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);
}

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