結果

問題 No.1011 Infinite Stairs
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2021-12-04 09:47:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 1,179 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 11,100 KB
実行使用メモリ 56,072 KB
最終ジャッジ日時 2023-09-20 19:40:06
合計ジャッジ時間 9,452 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
29,844 KB
testcase_01 AC 133 ms
29,724 KB
testcase_02 AC 138 ms
30,216 KB
testcase_03 AC 292 ms
44,796 KB
testcase_04 AC 345 ms
55,924 KB
testcase_05 AC 342 ms
56,072 KB
testcase_06 AC 129 ms
29,808 KB
testcase_07 AC 159 ms
33,548 KB
testcase_08 AC 129 ms
29,780 KB
testcase_09 AC 133 ms
29,908 KB
testcase_10 AC 155 ms
33,140 KB
testcase_11 AC 232 ms
42,884 KB
testcase_12 AC 142 ms
31,388 KB
testcase_13 AC 229 ms
42,444 KB
testcase_14 AC 141 ms
30,588 KB
testcase_15 AC 160 ms
32,864 KB
testcase_16 AC 336 ms
55,340 KB
testcase_17 AC 262 ms
45,480 KB
testcase_18 AC 194 ms
36,812 KB
testcase_19 AC 134 ms
30,136 KB
testcase_20 AC 155 ms
32,844 KB
testcase_21 AC 180 ms
37,188 KB
testcase_22 AC 275 ms
43,280 KB
testcase_23 AC 192 ms
36,488 KB
testcase_24 AC 178 ms
36,040 KB
testcase_25 AC 190 ms
36,380 KB
testcase_26 AC 161 ms
33,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0