結果

問題 No.612 Move on grid
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2021-12-30 21:00:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 508 ms / 2,500 ms
コード長 1,350 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 43,092 KB
最終ジャッジ日時 2023-12-16 10:45:03
合計ジャッジ時間 13,106 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 477 ms
43,092 KB
testcase_01 AC 484 ms
43,092 KB
testcase_02 AC 477 ms
43,092 KB
testcase_03 AC 483 ms
43,092 KB
testcase_04 AC 496 ms
43,092 KB
testcase_05 AC 498 ms
43,092 KB
testcase_06 AC 502 ms
43,092 KB
testcase_07 AC 508 ms
43,092 KB
testcase_08 AC 503 ms
43,092 KB
testcase_09 AC 499 ms
42,964 KB
testcase_10 AC 501 ms
43,092 KB
testcase_11 AC 488 ms
43,092 KB
testcase_12 AC 495 ms
43,092 KB
testcase_13 AC 489 ms
43,092 KB
testcase_14 AC 494 ms
43,092 KB
testcase_15 AC 491 ms
43,092 KB
testcase_16 AC 503 ms
43,092 KB
testcase_17 AC 496 ms
43,092 KB
testcase_18 AC 497 ms
43,092 KB
testcase_19 AC 503 ms
43,092 KB
testcase_20 AC 496 ms
43,092 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

T = int(input())
a,b,c,d,e = map(int,input().split())
a = abs(a)
b = abs(b)
c = abs(c)
mod = 10**9 + 7

M = max(a,b,c)

X = [0]*(2*M+1)
X[M+a] += 1
X[M-a] += 1
X[M+b] += 1
X[M-b] += 1
X[M+c] += 1
X[M-c] += 1
print(sum(convolve_pow(X,T,mod)[max(d+M*T,0):e+M*T+1])%mod)
0