結果

問題 No.391 CODING WAR
ユーザー rlangevinrlangevin
提出日時 2023-08-28 08:52:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 1,129 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 81,320 KB
最終ジャッジ日時 2023-08-28 08:52:45
合計ジャッジ時間 4,102 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,212 KB
testcase_01 AC 73 ms
71,204 KB
testcase_02 AC 69 ms
71,248 KB
testcase_03 AC 70 ms
71,152 KB
testcase_04 AC 71 ms
71,028 KB
testcase_05 AC 71 ms
71,176 KB
testcase_06 AC 71 ms
71,320 KB
testcase_07 AC 71 ms
71,252 KB
testcase_08 AC 72 ms
71,244 KB
testcase_09 AC 176 ms
81,240 KB
testcase_10 AC 158 ms
81,320 KB
testcase_11 AC 136 ms
81,160 KB
testcase_12 AC 71 ms
71,160 KB
testcase_13 AC 168 ms
81,316 KB
testcase_14 AC 159 ms
79,988 KB
testcase_15 AC 170 ms
80,288 KB
testcase_16 AC 132 ms
78,600 KB
testcase_17 AC 138 ms
79,192 KB
testcase_18 AC 121 ms
78,080 KB
testcase_19 AC 120 ms
78,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())

n = 2 * M + 5
mod = 10 ** 9 + 7
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod

ans = 0
pm = 1
for i in range(M, -1, -1):
    ans += pm * comb(M, i) * pow(i, N, mod)
    ans %= mod
    pm *= -1

print(ans)
0