結果

問題 No.1035 Color Box
ユーザー tamatotamato
提出日時 2020-04-24 21:29:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 66,700 KB
最終ジャッジ日時 2024-04-23 02:54:13
合計ジャッジ時間 3,137 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
65,972 KB
testcase_01 AC 48 ms
63,896 KB
testcase_02 AC 47 ms
63,920 KB
testcase_03 AC 53 ms
65,240 KB
testcase_04 AC 55 ms
66,700 KB
testcase_05 AC 53 ms
66,644 KB
testcase_06 AC 48 ms
63,960 KB
testcase_07 AC 51 ms
64,448 KB
testcase_08 AC 81 ms
65,392 KB
testcase_09 AC 61 ms
65,952 KB
testcase_10 AC 48 ms
64,440 KB
testcase_11 AC 48 ms
64,588 KB
testcase_12 AC 47 ms
64,400 KB
testcase_13 AC 71 ms
66,068 KB
testcase_14 AC 76 ms
65,608 KB
testcase_15 AC 81 ms
65,496 KB
testcase_16 AC 47 ms
64,416 KB
testcase_17 AC 48 ms
63,348 KB
testcase_18 AC 49 ms
64,792 KB
testcase_19 AC 85 ms
65,744 KB
testcase_20 AC 48 ms
64,436 KB
testcase_21 AC 48 ms
64,076 KB
testcase_22 AC 47 ms
63,376 KB
testcase_23 AC 47 ms
64,176 KB
testcase_24 AC 48 ms
64,972 KB
testcase_25 AC 49 ms
63,576 KB
testcase_26 AC 48 ms
63,820 KB
testcase_27 AC 47 ms
64,356 KB
testcase_28 AC 46 ms
63,504 KB
testcase_29 AC 46 ms
64,844 KB
testcase_30 AC 48 ms
65,448 KB
testcase_31 AC 49 ms
64,900 KB
testcase_32 AC 48 ms
63,928 KB
testcase_33 AC 49 ms
64,460 KB
testcase_34 AC 50 ms
64,520 KB
testcase_35 AC 49 ms
63,776 KB
testcase_36 AC 48 ms
64,324 KB
testcase_37 AC 48 ms
64,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    # comb init
    nmax = 2 * 10 ** 5 + 10  # change here
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

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

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


if __name__ == '__main__':
    main()
0