結果
問題 | No.2877 Gunegune Hyperion |
ユーザー |
![]() |
提出日時 | 2024-08-30 01:52:23 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,284 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 361,600 KB |
最終ジャッジ日時 | 2024-09-15 09:08:44 |
合計ジャッジ時間 | 69,803 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 TLE * 1 |
ソースコード
import numpy as npfft, ifft = np.fft.rfft, np.fft.irfftdef convolve(f, g):fft_len = 1while 2 * fft_len < len(f) + len(g) - 1:fft_len *= 2fft_len *= 2h = ifft(fft(f, fft_len, axis=0) @ fft(g, fft_len, axis=0), 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, c = convolve(f1, g1) % p, 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 resdef main():mod = 998244353P = np.array([[[499122177, 0, 0], [332748118, 0, 0], [0, 0, 0]],[[0, 499122177, 0], [0, 332748118, 332748118], [0, 665496236, 332748118]],])v = np.array([[199648871, 0, 0], [0, 199648871, 598946612]])N, H = map(int, input().split())P = poly_pow(P, N - 1, mod)print(sum(np.sum(v[i] @ P[H - i :] % mod) for i in range(2)) % mod)if __name__ == "__main__":main()