結果

問題 No.802 だいたい等差数列
ユーザー tempura_pptempura_pp
提出日時 2019-03-10 01:42:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 169,040 KB
実行使用メモリ 33,744 KB
最終ジャッジ日時 2023-09-14 12:07:54
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 46 ms
26,668 KB
testcase_11 AC 61 ms
33,124 KB
testcase_12 AC 25 ms
16,832 KB
testcase_13 AC 57 ms
32,424 KB
testcase_14 AC 40 ms
24,168 KB
testcase_15 AC 21 ms
14,360 KB
testcase_16 AC 44 ms
25,112 KB
testcase_17 AC 15 ms
10,044 KB
testcase_18 AC 13 ms
8,876 KB
testcase_19 AC 30 ms
19,564 KB
testcase_20 AC 46 ms
26,560 KB
testcase_21 AC 66 ms
33,656 KB
testcase_22 AC 65 ms
33,744 KB
testcase_23 AC 19 ms
12,672 KB
testcase_24 AC 16 ms
10,104 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 15 ms
9,992 KB
testcase_27 AC 14 ms
8,744 KB
testcase_28 AC 28 ms
16,984 KB
testcase_29 AC 60 ms
33,312 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 17 ms
12,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
const ll mod=1e9+7 ;


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
	fact.resize(n+1);
	inv.resize(n+1);
	invfact.resize(n+1);
	fact[0]=inv[0]=invfact[0]=1;
	inv[1]=1;
	rep(i,n){
		fact[i+1]=fact[i]*(i+1)%mod;
		if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
		invfact[i+1]=invfact[i]*inv[i+1]%mod;
	}
}
ll perm(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return fact[n]*invfact[n-k]%mod;
}
ll comb(ll n,ll k){
	if(n<0||k<0||k>n)return 0;
	return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}

int main(){
	ll n,m,d1,d2;
	cin>>n>>m>>d1>>d2;
	assert(2<=n&&n<=300000);
	assert(1<=m&&m<=1000000);
	assert(0<=d1&&d1<=d2&&d2<=m);
	m-=(n-1)*(d1-1);
	d2-=d1-1;
	mod_build(max(m+1,n));
	ll ans=0;
	rep(i,n){
		ll ret=comb(m-d2*i,n)*comb(n-1,i)%mod;
		if(i%2)ans+=mod-ret;
		else ans+=ret;
	}
	cout<<ans%mod<<endl;
	return 0;
}
0