結果
| 問題 |
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 np
fft, ifft = np.fft.rfft, np.fft.irfft
def convolve(f, g):
fft_len = 1
while 2 * fft_len < len(f) + len(g) - 1:
fft_len *= 2
fft_len *= 2
h = 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) % p
b = (convolve(f1 + f2, g1 + g2) - a - c) % p
return ((a << 30) + (b << 15) + c) % p
def 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 >>= 1
return res
def main():
mod = 998244353
P = 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()
寝癖