結果

問題 No.802 だいたい等差数列
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-18 22:00:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 973 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 65,336 KB
実行使用メモリ 22,104 KB
最終ジャッジ日時 2023-09-26 10:47:48
合計ジャッジ時間 25,776 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 3 ms
5,416 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 5 ms
5,428 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 811 ms
21,832 KB
testcase_21 WA -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 803 ms
21,728 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
testcase_30 AC 2 ms
5,588 KB
testcase_31 AC 2 ms
5,468 KB
testcase_32 WA -
testcase_33 AC 475 ms
15,816 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<=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)*comb(x-i*(D2-D1+1)+N,N);
        if(i%2==0) (ans += r)%=inf;
        else (ans += -r+inf)%=inf;
    }
    cout << ans << endl;
}
0