結果

問題 No.1035 Color Box
ユーザー H3PO4H3PO4
提出日時 2021-09-10 10:04:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 16,068 KB
最終ジャッジ日時 2023-08-30 20:32:34
合計ジャッジ時間 7,139 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 324 ms
15,848 KB
testcase_01 AC 80 ms
15,984 KB
testcase_02 AC 79 ms
15,948 KB
testcase_03 AC 97 ms
16,068 KB
testcase_04 AC 100 ms
15,932 KB
testcase_05 AC 87 ms
15,944 KB
testcase_06 AC 80 ms
15,928 KB
testcase_07 AC 82 ms
16,036 KB
testcase_08 AC 292 ms
16,020 KB
testcase_09 AC 168 ms
15,852 KB
testcase_10 AC 79 ms
15,920 KB
testcase_11 AC 77 ms
16,040 KB
testcase_12 AC 76 ms
15,976 KB
testcase_13 AC 253 ms
15,980 KB
testcase_14 AC 284 ms
16,032 KB
testcase_15 AC 322 ms
15,980 KB
testcase_16 AC 81 ms
15,904 KB
testcase_17 AC 80 ms
16,004 KB
testcase_18 AC 78 ms
15,984 KB
testcase_19 AC 325 ms
15,872 KB
testcase_20 AC 79 ms
15,984 KB
testcase_21 AC 78 ms
15,932 KB
testcase_22 AC 77 ms
16,004 KB
testcase_23 AC 80 ms
16,048 KB
testcase_24 AC 76 ms
15,848 KB
testcase_25 AC 78 ms
15,868 KB
testcase_26 AC 78 ms
15,888 KB
testcase_27 AC 76 ms
16,056 KB
testcase_28 AC 78 ms
15,852 KB
testcase_29 AC 79 ms
15,992 KB
testcase_30 AC 78 ms
16,036 KB
testcase_31 AC 77 ms
16,008 KB
testcase_32 AC 80 ms
16,048 KB
testcase_33 AC 77 ms
15,888 KB
testcase_34 AC 79 ms
15,912 KB
testcase_35 AC 75 ms
16,040 KB
testcase_36 AC 77 ms
16,004 KB
testcase_37 AC 79 ms
15,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
MAX = 10 ** 5 + 10
# https://tjkendev.github.io/procon-library/python/math/factorial.html から拝借しています。
fact = [1] * (MAX + 1)
rfact = [1] * (MAX + 1)
r = 1
for i in range(1, MAX + 1):
    fact[i] = r = r * i % MOD
rfact[MAX] = r = pow(fact[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
    rfact[i - 1] = r = r * i % MOD


def comb(n, k, error=0):
    if not 0 <= k <= n:
        return error
    return fact[n] * rfact[k] * rfact[n - k] % MOD


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