結果

問題 No.802 だいたい等差数列
ユーザー addeight2addeight2
提出日時 2019-03-19 10:31:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 145,420 KB
実行使用メモリ 23,996 KB
最終ジャッジ日時 2023-10-11 15:16:48
合計ジャッジ時間 4,328 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,428 KB
testcase_01 AC 2 ms
5,420 KB
testcase_02 AC 2 ms
5,480 KB
testcase_03 AC 2 ms
5,428 KB
testcase_04 AC 2 ms
5,408 KB
testcase_05 AC 2 ms
5,436 KB
testcase_06 AC 2 ms
5,480 KB
testcase_07 AC 2 ms
5,404 KB
testcase_08 AC 2 ms
5,492 KB
testcase_09 AC 2 ms
5,540 KB
testcase_10 AC 19 ms
21,956 KB
testcase_11 AC 23 ms
23,544 KB
testcase_12 AC 21 ms
22,560 KB
testcase_13 AC 22 ms
23,256 KB
testcase_14 AC 23 ms
22,900 KB
testcase_15 AC 21 ms
22,192 KB
testcase_16 AC 23 ms
23,160 KB
testcase_17 AC 22 ms
23,140 KB
testcase_18 AC 22 ms
23,172 KB
testcase_19 AC 24 ms
23,716 KB
testcase_20 AC 27 ms
23,724 KB
testcase_21 AC 27 ms
23,704 KB
testcase_22 AC 23 ms
23,996 KB
testcase_23 AC 24 ms
23,792 KB
testcase_24 AC 23 ms
23,672 KB
testcase_25 AC 18 ms
21,824 KB
testcase_26 AC 9 ms
13,648 KB
testcase_27 AC 22 ms
23,320 KB
testcase_28 AC 14 ms
17,860 KB
testcase_29 AC 27 ms
23,672 KB
testcase_30 AC 2 ms
5,472 KB
testcase_31 AC 2 ms
5,472 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 13 ms
17,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
const ll MOD=1e9+7;
const int MAX_N=3e5,MAX_M=1e6;
ll fact[MAX_N+MAX_M],ifact[MAX_N+MAX_M];
int N,M,D1,D2,D;
ll minv(ll n){
	ll m=MOD-2,ret=1;
	while(m){
		if(m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}
ll cmb(ll n,ll m){
	return fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;
}
int main(){
	cin>>N>>M>>D1>>D2;
	D=D2-D1;
	ll x=M-1-(ll)D1*(N-1);
	ll ans=0;
	fact[0]=1;
	REP(i,N+M-1){
		fact[i+1]=fact[i]*(i+1)%MOD;
	}
	ifact[N+M-1]=minv(fact[N+M-1]);
	for(int i=N+M-2;i>=0;i--){
		ifact[i]=ifact[i+1]*(i+1)%MOD;
	}
	REP(i,N){
		ll sgn;
		if(i%2==0){
			sgn=1;
		}else{
			sgn=-1;
		}
		ll y=x-(ll)i*(D+1)+N;
		if(y-N>=0){
			ans+=sgn*(cmb(N-1,i)*cmb(y,N))%MOD;
			ans+=MOD;
			ans%=MOD;
		}
	}
	cout<<ans<<endl;
}
0