結果

問題 No.834 Random Walk Trip
ユーザー tempura_pptempura_pp
提出日時 2019-03-23 18:28:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 725 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 12,048 KB
実行使用メモリ 88,540 KB
最終ジャッジ日時 2023-10-24 14:08:27
合計ジャッジ時間 4,758 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,236 KB
testcase_01 AC 33 ms
10,236 KB
testcase_02 AC 32 ms
10,236 KB
testcase_03 AC 31 ms
10,236 KB
testcase_04 AC 30 ms
10,236 KB
testcase_05 AC 29 ms
10,236 KB
testcase_06 AC 31 ms
10,236 KB
testcase_07 AC 31 ms
10,236 KB
testcase_08 AC 31 ms
10,236 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 31 ms
10,236 KB
testcase_12 AC 30 ms
10,236 KB
testcase_13 AC 32 ms
10,236 KB
testcase_14 AC 30 ms
10,236 KB
testcase_15 AC 31 ms
10,256 KB
testcase_16 AC 39 ms
10,912 KB
testcase_17 WA -
testcase_18 AC 155 ms
24,004 KB
testcase_19 AC 721 ms
88,540 KB
testcase_20 AC 148 ms
23,212 KB
testcase_21 WA -
testcase_22 AC 30 ms
10,236 KB
testcase_23 WA -
testcase_24 AC 62 ms
13,444 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def mod_build(n, mod) :
    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, mod) : 
    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 = map(int, input().split())
    if n == 1 : return 1
    mod = 1000000007
    fact, inv_fact = mod_build(m,mod)
    i = m//2
    ans = 0
    idx = [i+n*j for j in range(-m,m) if i+n*j>=0 and i+n*j <=n ]
    for j in idx : 
        ans += comb(m,j,fact,inv_fact,mod)
    return ans

print(solve())
0