結果
問題 | No.93 ペガサス |
ユーザー |
![]() |
提出日時 | 2020-04-23 17:18:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 481 ms / 5,000 ms |
コード長 | 1,064 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 44,536 KB |
最終ジャッジ日時 | 2024-10-13 16:53:44 |
合計ジャッジ時間 | 11,686 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesimport numpy as npMOD = 10 ** 9 + 7N = int(read())if N == 1:print(1)exit()M = N // 2def update_dp(f, g):newf = np.zeros(len(f) + 1, np.int64)newg = newf.copy()newg[:-1] = f + f + gnewf[1:] = f + gnewf %= MODnewg %= MODreturn newf, newgf = np.array([0, 1], np.int64)g = np.array([0, 0], np.int64)for _ in range((N - 2) // 2):f, g = update_dp(f, g)A = f + gif N & 1:f, g = update_dp(f, g)B = f + gdef convolve(A, B):A1, A2 = divmod(A, 1 << 16)B1, B2 = divmod(B, 1 << 16)X = np.convolve(A1, B1) % MODZ = np.convolve(A2, B2) % MODY = (np.convolve(A1 + A2, B1 + B2) - X - Z) % MODreturn ((X << 32) + (Y << 16) + Z) % MODA = convolve(A, B)fact = [1, 1]for n in range(2, N + 10):fact.append(fact[-1] * n % MOD)fact = np.array(fact, dtype=np.int64)A *= fact[:N+1]A[1 - (N & 1)::2] *= - 1A %= MODanswer = A.sum() % MODprint(answer)