結果
問題 | No.1035 Color Box |
ユーザー |
![]() |
提出日時 | 2020-04-25 16:44:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,175 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 48,872 KB |
最終ジャッジ日時 | 2024-11-07 07:44:14 |
合計ジャッジ時間 | 24,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 WA * 19 |
ソースコード
import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesimport numpy as npMOD = 10 ** 9 + 7def 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] %= MODfor n in range(1, Lsq):A[n] *= A[n - 1, -1]A[n] %= MODreturn A.ravel()[:L]def make_fact(U, MOD=MOD):x = np.arange(U, dtype=np.int64)x[0] = 1fact = 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 = Falsefact_inv.flags.writeable = Falsereturn fact, fact_invfact, fact_inv = make_fact(10 ** 5 + 10)N, M = map(int, read().split())def power(A, n):if n == 1:return AB = power(A, n // 2)B = B * B % MODreturn A * B % MOD if n & 1 else Bcomb = fact[M] * fact_inv[: M + 1] % MOD * fact_inv[: M + 1][::-1] % MODpower = power(np.arange(M + 1, dtype=np.int64), N)x = comb * power % MODx[1::2] *= (-1)print(x.sum() % MOD)