結果

問題 No.391 CODING WAR
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-08-01 22:24:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 845 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 15,952 KB
最終ジャッジ日時 2023-09-22 18:25:02
合計ジャッジ時間 7,526 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,724 KB
testcase_01 AC 17 ms
7,860 KB
testcase_02 AC 16 ms
7,896 KB
testcase_03 AC 15 ms
7,844 KB
testcase_04 AC 16 ms
7,852 KB
testcase_05 AC 17 ms
7,856 KB
testcase_06 AC 15 ms
7,728 KB
testcase_07 AC 17 ms
7,728 KB
testcase_08 AC 16 ms
7,796 KB
testcase_09 AC 845 ms
15,856 KB
testcase_10 AC 757 ms
15,928 KB
testcase_11 AC 660 ms
15,952 KB
testcase_12 AC 15 ms
7,724 KB
testcase_13 AC 805 ms
15,812 KB
testcase_14 AC 653 ms
13,872 KB
testcase_15 AC 749 ms
14,508 KB
testcase_16 AC 446 ms
11,980 KB
testcase_17 AC 516 ms
12,640 KB
testcase_18 AC 357 ms
11,196 KB
testcase_19 AC 369 ms
11,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
n, m = map(int, input().split())
fa = [1] * (m + 1)
fi = [1] * (m + 1)
for i in range(1, m + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(m + 1):
    cnt = comb(m, i) * pow(i, n, mod)
    if (m - i) & 1:
        ans -= cnt
    else:
        ans += cnt
print(ans % mod)
0