結果

問題 No.802 だいたい等差数列
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-18 22:04:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 577 ms
コンパイル使用メモリ 66,484 KB
実行使用メモリ 22,032 KB
最終ジャッジ日時 2023-09-26 10:57:10
合計ジャッジ時間 16,981 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,444 KB
testcase_01 AC 3 ms
5,384 KB
testcase_02 AC 5 ms
5,432 KB
testcase_03 AC 3 ms
5,500 KB
testcase_04 WA -
testcase_05 AC 5 ms
5,436 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
5,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 700 ms
19,788 KB
testcase_13 WA -
testcase_14 AC 719 ms
21,796 KB
testcase_15 AC 792 ms
22,000 KB
testcase_16 AC 758 ms
21,828 KB
testcase_17 AC 740 ms
21,780 KB
testcase_18 AC 780 ms
21,736 KB
testcase_19 AC 808 ms
21,780 KB
testcase_20 AC 812 ms
21,776 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 793 ms
21,916 KB
testcase_24 AC 796 ms
22,000 KB
testcase_25 AC 788 ms
22,032 KB
testcase_26 WA -
testcase_27 AC 792 ms
21,828 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
5,412 KB
testcase_31 AC 2 ms
5,468 KB
testcase_32 AC 2 ms
5,412 KB
testcase_33 AC 467 ms
15,640 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(max(N,M));
    ll ans = 0;
	ll 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))%inf;
        if(i%2==0) (ans += r)%=inf;
        else (ans += -r+inf)%=inf;
    }
    cout << ans << endl;
}
0