結果

問題 No.802 だいたい等差数列
ユーザー tempura_pptempura_pp
提出日時 2019-03-09 20:25:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 89,620 KB
実行使用メモリ 33,716 KB
最終ジャッジ日時 2023-09-14 12:06:25
合計ジャッジ時間 2,812 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 49 ms
26,900 KB
testcase_11 AC 68 ms
32,964 KB
testcase_12 AC 28 ms
16,820 KB
testcase_13 AC 66 ms
32,636 KB
testcase_14 AC 46 ms
24,284 KB
testcase_15 AC 22 ms
14,184 KB
testcase_16 AC 46 ms
25,000 KB
testcase_17 AC 16 ms
9,836 KB
testcase_18 AC 13 ms
8,560 KB
testcase_19 AC 34 ms
19,320 KB
testcase_20 AC 51 ms
26,564 KB
testcase_21 AC 71 ms
33,364 KB
testcase_22 AC 73 ms
33,716 KB
testcase_23 AC 21 ms
12,480 KB
testcase_24 AC 16 ms
10,020 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 16 ms
10,020 KB
testcase_27 AC 14 ms
8,832 KB
testcase_28 AC 30 ms
17,092 KB
testcase_29 AC 72 ms
33,640 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 17 ms
12,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
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,int k){
	if(n<0||k<0||k>n)return 0;
	return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll pow(ll n,ll k){
	ll ret=1;
	while(k){
		if(k&1)ret=ret*n%mod;
		n=n*n%mod;
		k>>=1;
	}
	return ret;
}


int main(){
	ll n,m,d1,d2;
	cin>>n>>m>>d1>>d2;
	m-=(n-1)*(d1-1);
	d2-=d1-1;
	mod_build(max(m+5,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;

	rep(i,5000){
		ll n=1000+rand()%2000;
		ll m=n+rand()%7000;
		ll d1=0;
		ll d2=rand()%m;
		//if(m+n<3000)cout<<n<<" "<<m<<" "<<d1<<" "<<d2<<endl;
	}
	return 0;
}
0