結果

問題 No.802 だいたい等差数列
ユーザー chocoruskchocorusk
提出日時 2019-03-17 22:04:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,520 bytes
コンパイル時間 1,096 ms
コンパイル使用メモリ 95,376 KB
実行使用メモリ 28,292 KB
最終ジャッジ日時 2023-09-22 06:25:15
合計ジャッジ時間 2,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,420 KB
testcase_01 AC 2 ms
5,476 KB
testcase_02 AC 2 ms
5,524 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
5,480 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
5,424 KB
testcase_07 AC 2 ms
5,472 KB
testcase_08 AC 2 ms
5,608 KB
testcase_09 AC 1 ms
5,620 KB
testcase_10 AC 20 ms
22,552 KB
testcase_11 AC 26 ms
28,168 KB
testcase_12 AC 15 ms
17,932 KB
testcase_13 AC 26 ms
28,160 KB
testcase_14 AC 20 ms
24,220 KB
testcase_15 AC 13 ms
14,492 KB
testcase_16 AC 22 ms
24,224 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 18 ms
20,088 KB
testcase_20 AC 25 ms
24,104 KB
testcase_21 AC 30 ms
28,272 KB
testcase_22 AC 26 ms
28,292 KB
testcase_23 AC 14 ms
16,080 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
5,424 KB
testcase_26 AC 11 ms
13,880 KB
testcase_27 AC 9 ms
11,372 KB
testcase_28 AC 17 ms
17,944 KB
testcase_29 AC 30 ms
28,276 KB
testcase_30 AC 2 ms
5,404 KB
testcase_31 AC 2 ms
5,440 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 10 ms
13,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <utility>
#include <functional>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[1500001], invf[1500001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(x<y) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int n, m, d1, d2; cin>>n>>m>>d1>>d2;
    if((ll)(m-1)<(ll)d1*(ll)(n-1)){
        cout<<0<<endl;
        return 0;
    }
    m-=d1*(n-1);
    d2-=d1;
    fac(n+m);
    ll ct[300001];
    for(int i=0; i<n; i++){
        if((ll)i*(ll)(d2+1)>=(ll)m){
            ct[i]=0; continue;
        }
        ll m1=m-1-(d2+1)*i;
        ct[i]=comb(n-1, i)*comb(m1+n, n)%MOD;
    }
    ll ans=0;
    for(int i=0; i<n; i++){
        if(i&1) ans+=(MOD-ct[i]);
        else ans+=ct[i];
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
0