結果
| 問題 |
No.980 Fibonacci Convolution Hard
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2020-12-10 16:46:36 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,235 bytes |
| コンパイル時間 | 234 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 446,952 KB |
| 最終ジャッジ日時 | 2024-09-19 20:38:04 |
| 合計ジャッジ時間 | 8,425 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 16 |
ソースコード
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
mod = 10 ** 9 + 7
def convolve(A, B):
n = len(A) + len(B) - 1
fftlen = 1 << (n-1).bit_length()
fa = np.fft.rfft(A, fftlen)
fb = np.fft.rfft(B, fftlen)
inv = (np.fft.irfft(fa * fb, fftlen) + 0.5).astype(np.int64)
return inv[:n]
def mod_convolve_10(A, B, mod):
a1, a2 = np.divmod(A, 1 << 20)
a2, a3 = np.divmod(a2, 1 << 10)
b1, b2 = np.divmod(B, 1 << 20)
b2, b3 = np.divmod(b2, 1 << 10)
x = convolve(a1, b1) % mod
y = convolve(a2, b2) % mod
z = convolve(a3, b3) % mod
xy = (convolve(a1 + a2, b1 + b2) - (x + y)) % mod
yz = (convolve(a2 + a3, b2 + b3) - (y + z)) % mod
zx = (convolve(a3 + a1, b3 + b1) - (z + x)) % mod
res = ((((x << 20) % mod) << 20) +
(((xy << 20) % mod) << 10) +
((y + zx) << 20) +
(yz << 10) % mod + z) % mod
return res
p = int(input())
Q = int(input())
query = np.array([input() for _ in range(Q)], dtype=np.intc)
U = 2 * 10 ** 6
A = [0, 1]
for _ in range(2, U+1):
A.append((p * A[-1] + A[-2]) % mod)
A = np.array(A, dtype=np.int64)
B = mod_convolve_10(A, A, mod)
ans = B[query - 2]
print(*ans, sep="\n")
tktk_snsn