結果

問題 No.1035 Color Box
ユーザー maspymaspy
提出日時 2020-04-25 16:44:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,175 bytes
コンパイル時間 398 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 48,632 KB
最終ジャッジ日時 2024-04-24 22:32:38
合計ジャッジ時間 25,036 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 550 ms
48,632 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 518 ms
45,964 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 540 ms
48,128 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 516 ms
45,580 KB
testcase_12 WA -
testcase_13 AC 541 ms
47,344 KB
testcase_14 AC 547 ms
47,984 KB
testcase_15 AC 563 ms
48,384 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 575 ms
48,620 KB
testcase_20 WA -
testcase_21 AC 530 ms
45,588 KB
testcase_22 AC 523 ms
45,584 KB
testcase_23 AC 518 ms
45,580 KB
testcase_24 AC 514 ms
45,708 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 516 ms
46,096 KB
testcase_29 AC 511 ms
46,052 KB
testcase_30 WA -
testcase_31 AC 514 ms
45,832 KB
testcase_32 AC 517 ms
45,972 KB
testcase_33 AC 508 ms
45,968 KB
testcase_34 AC 516 ms
45,844 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 522 ms
45,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

MOD = 10 ** 9 + 7


def cumprod(A, MOD=MOD):
    L = len(A)
    Lsq = int(L**.5 + 1)
    A = np.resize(A, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        A[:, n] *= A[:, n - 1]
        A[:, n] %= MOD
    for n in range(1, Lsq):
        A[n] *= A[n - 1, -1]
        A[n] %= MOD
    return A.ravel()[:L]


def make_fact(U, MOD=MOD):
    x = np.arange(U, dtype=np.int64)
    x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64)
    x[0] = pow(int(fact[-1]), MOD - 2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    fact.flags.writeable = False
    fact_inv.flags.writeable = False
    return fact, fact_inv


fact, fact_inv = make_fact(10 ** 5 + 10)
N, M = map(int, read().split())


def power(A, n):
    if n == 1:
        return A
    B = power(A, n // 2)
    B = B * B % MOD
    return A * B % MOD if n & 1 else B


comb = fact[M] * fact_inv[: M + 1] % MOD * fact_inv[: M + 1][::-1] % MOD
power = power(np.arange(M + 1, dtype=np.int64), N)
x = comb * power % MOD
x[1::2] *= (-1)
print(x.sum() % MOD)
0