結果
| 問題 |
No.1011 Infinite Stairs
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-12-04 09:47:44 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 674 ms / 2,000 ms |
| コード長 | 1,179 bytes |
| コンパイル時間 | 83 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 67,936 KB |
| 最終ジャッジ日時 | 2024-07-06 14:36:15 |
| 合計ジャッジ時間 | 17,471 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
import numpy as np
def convolve(f, g):
tf = np.array(f, np.int64)
tg = np.array(g, np.int64)
fft_len = 1
while 2 * fft_len < len(tf) + len(tg) - 1:
fft_len *= 2
fft_len *= 2
# フーリエ変換
Ff = np.fft.rfft(tf, fft_len)
Fg = np.fft.rfft(tg, fft_len)
# 各点積
Fh = Ff * Fg
# フーリエ逆変換
h = np.fft.irfft(Fh, fft_len)
# 小数になっているので、整数にまるめる
h = np.rint(h).astype(np.int64)
return h[:len(f) + len(g) - 1]
def convolve2(f,g,p):
f1,f2 = np.divmod(f,1<<15)
g1,g2 = np.divmod(g,1<<15)
a = convolve(f1,g1)%p
c = convolve(f2,g2)%p
b = (convolve(f1+f2,g1+g2) - a - c)%p
h = (a<<30) + (b<<15) + c
return h%p
def convolve_pow(f,n,p):
nbit = list(str(bin(n))[2:])
nbit = [int(i) for i in nbit]
N = len(f)
C = [1] + [0]*(N-1)
B = f
for i in range(len(nbit)):
if nbit[-1-i] == 1:
C = convolve2(C,B,p)
B = convolve2(B,B,p)
return C
N,d,K = map(int,input().split())
mod = 10**9 + 7
A = [0] + [1]*d
print(convolve_pow(A,N,mod)[K])