結果

問題 No.802 だいたい等差数列
ユーザー tempura_pptempura_pp
提出日時 2019-03-09 19:45:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 727 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 110,020 KB
最終ジャッジ日時 2023-09-14 12:06:21
合計ジャッジ時間 10,257 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,408 KB
testcase_01 AC 17 ms
8,296 KB
testcase_02 AC 19 ms
8,508 KB
testcase_03 AC 17 ms
8,292 KB
testcase_04 AC 18 ms
8,552 KB
testcase_05 AC 16 ms
7,756 KB
testcase_06 AC 18 ms
8,556 KB
testcase_07 AC 18 ms
8,432 KB
testcase_08 AC 18 ms
8,344 KB
testcase_09 AC 18 ms
8,560 KB
testcase_10 AC 432 ms
86,992 KB
testcase_11 AC 637 ms
108,392 KB
testcase_12 AC 390 ms
54,432 KB
testcase_13 AC 602 ms
105,956 KB
testcase_14 AC 520 ms
78,344 KB
testcase_15 AC 273 ms
45,372 KB
testcase_16 AC 518 ms
81,764 KB
testcase_17 AC 282 ms
31,556 KB
testcase_18 AC 236 ms
27,036 KB
testcase_19 AC 443 ms
63,028 KB
testcase_20 AC 631 ms
86,500 KB
testcase_21 AC 726 ms
109,892 KB
testcase_22 AC 643 ms
109,880 KB
testcase_23 AC 356 ms
39,336 KB
testcase_24 AC 16 ms
7,964 KB
testcase_25 AC 16 ms
7,788 KB
testcase_26 AC 288 ms
31,504 KB
testcase_27 AC 251 ms
27,796 KB
testcase_28 AC 419 ms
54,820 KB
testcase_29 AC 727 ms
110,020 KB
testcase_30 AC 16 ms
7,804 KB
testcase_31 AC 16 ms
7,936 KB
testcase_32 AC 16 ms
7,976 KB
testcase_33 AC 168 ms
40,488 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