結果

問題 No.802 だいたい等差数列
ユーザー tempura_pptempura_pp
提出日時 2019-03-09 19:42:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 818 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 109,972 KB
最終ジャッジ日時 2023-09-14 12:06:04
合計ジャッジ時間 10,001 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,492 KB
testcase_01 AC 17 ms
8,236 KB
testcase_02 AC 19 ms
8,452 KB
testcase_03 RE -
testcase_04 AC 18 ms
8,560 KB
testcase_05 RE -
testcase_06 AC 18 ms
8,476 KB
testcase_07 AC 18 ms
8,444 KB
testcase_08 AC 18 ms
8,292 KB
testcase_09 AC 18 ms
8,452 KB
testcase_10 AC 432 ms
87,136 KB
testcase_11 AC 636 ms
108,336 KB
testcase_12 AC 387 ms
54,292 KB
testcase_13 AC 602 ms
106,004 KB
testcase_14 AC 520 ms
78,448 KB
testcase_15 AC 275 ms
45,380 KB
testcase_16 AC 519 ms
81,856 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 442 ms
62,932 KB
testcase_20 AC 625 ms
86,648 KB
testcase_21 AC 730 ms
109,932 KB
testcase_22 AC 648 ms
109,916 KB
testcase_23 AC 353 ms
39,348 KB
testcase_24 AC 16 ms
7,840 KB
testcase_25 AC 16 ms
7,912 KB
testcase_26 AC 288 ms
31,572 KB
testcase_27 AC 251 ms
27,880 KB
testcase_28 AC 422 ms
54,840 KB
testcase_29 AC 726 ms
109,972 KB
testcase_30 AC 16 ms
7,868 KB
testcase_31 AC 16 ms
7,924 KB
testcase_32 RE -
testcase_33 AC 167 ms
40,360 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(m+1)
    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