結果
問題 | No.2877 Gunegune Hyperion |
ユーザー |
![]() |
提出日時 | 2024-08-30 00:46:35 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,470 bytes |
コンパイル時間 | 690 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 437,136 KB |
最終ジャッジ日時 | 2024-09-10 18:01:37 |
合計ジャッジ時間 | 102,600 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 TLE * 1 |
ソースコード
import numpy as npdef convolve(f, g):fft_len = 1while 2 * fft_len < len(f) + len(g) - 1:fft_len *= 2fft_len *= 2Ff = np.fft.rfft(f, fft_len, axis=0)Fg = np.fft.rfft(g, fft_len, axis=0)Fh = Ff @ Fgh = np.fft.irfft(Fh, fft_len, axis=0)h = np.rint(h).astype(np.int64)return h[: len(f) + len(g) - 1]def convolution(f, g, p=998244353):f1, f2 = np.divmod(f, 1 << 15)g1, g2 = np.divmod(g, 1 << 15)a = convolve(f1, g1) % pc = convolve(f2, g2) % pb = (convolve(f1 + f2, g1 + g2) - a - c) % preturn ((a << 30) + (b << 15) + c) % pdef poly_pow(f, n, p=998244353):res = np.eye(3, dtype=np.int64).reshape(1, 3, 3)while n:if n & 1:res = convolution(res, f, p)f = convolution(f, f, p)n >>= 1return resmod = 998244353inv2, inv3, inv5 = pow(2, mod - 2, mod), pow(3, mod - 2, mod), pow(5, mod - 2, mod)P = np.array([[[inv2, 0, 0], [inv3, 0, 0], [0, 0, 0]],[[0, inv2, 0], [0, inv3, inv3], [0, 2 * inv3, inv3]],])v = np.array([[2 * inv5 % mod, 0, 0], [0, 2 * inv5 % mod, inv5]])if __name__ == "__main__":N, H = map(int, input().split())P = poly_pow(P, N - 1, mod)A = [v[i] @ P[H - i :] % mod for i in range(2)]ans = 0for a in A:for row in a:for x in row:ans += xif ans >= mod:ans -= modprint(ans)