結果

問題 No.802 だいたい等差数列
ユーザー tempura_pptempura_pp
提出日時 2019-03-09 19:46:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 97,136 KB
最終ジャッジ日時 2023-09-14 12:06:10
合計ジャッジ時間 5,524 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
75,864 KB
testcase_01 AC 78 ms
75,692 KB
testcase_02 AC 85 ms
76,192 KB
testcase_03 AC 84 ms
76,140 KB
testcase_04 AC 83 ms
75,860 KB
testcase_05 AC 74 ms
71,400 KB
testcase_06 AC 83 ms
76,076 KB
testcase_07 AC 85 ms
75,984 KB
testcase_08 AC 79 ms
75,804 KB
testcase_09 AC 80 ms
76,060 KB
testcase_10 AC 118 ms
92,404 KB
testcase_11 AC 139 ms
96,636 KB
testcase_12 AC 127 ms
85,816 KB
testcase_13 AC 136 ms
96,148 KB
testcase_14 AC 156 ms
91,024 KB
testcase_15 AC 119 ms
84,140 KB
testcase_16 AC 153 ms
91,880 KB
testcase_17 AC 129 ms
81,240 KB
testcase_18 AC 123 ms
80,620 KB
testcase_19 AC 147 ms
87,772 KB
testcase_20 AC 158 ms
92,280 KB
testcase_21 AC 167 ms
97,028 KB
testcase_22 AC 142 ms
96,744 KB
testcase_23 AC 141 ms
83,016 KB
testcase_24 AC 74 ms
71,412 KB
testcase_25 AC 72 ms
71,404 KB
testcase_26 AC 127 ms
81,188 KB
testcase_27 AC 113 ms
80,720 KB
testcase_28 AC 150 ms
86,208 KB
testcase_29 AC 166 ms
97,136 KB
testcase_30 AC 76 ms
71,084 KB
testcase_31 AC 74 ms
71,152 KB
testcase_32 AC 75 ms
71,404 KB
testcase_33 AC 96 ms
82,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007

def mod_build(n) :
    fact = [1]*(n+1)
    inv_fact = [1]*(n+1)
    for i in range(1,n+1):
        fact[i] = fact[i-1]*i %mod
    inv_fact[n] = pow(fact[n],mod-2,mod)
    for i in range(n,0,-1):
        inv_fact[i-1] = inv_fact[i]*i %mod
    return fact, inv_fact
    
def comb(n,k,fact,inv_fact) : 
    if n<0 or k<0 or k>n :
        return 0
    return fact[n]*inv_fact[k]*inv_fact[n-k]%mod

def solve(n,m,d1,d2) :
    m = m-(n-1)*(d1-1)
    if m<0 :
        return 0
    d2=d2-d1+1
    fact, inv_fact = mod_build(max(m+1,n))
    ans = 0
    for i in range(0,n):
        ret=comb(m-d2*i,n,fact,inv_fact)*comb(n-1,i,fact,inv_fact)%mod
        if i%2 ==1 : 
            ans+=mod-ret
        else :
            ans+=ret
    return ans%mod

n, m, d1, d2 = map(int, input().split())
print(solve(n, m, d1, d2))
0