結果

問題 No.612 Move on grid
ユーザー maspymaspy
提出日時 2020-01-02 15:03:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 570 ms / 2,500 ms
コード長 1,419 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 45,172 KB
最終ジャッジ日時 2024-05-02 06:29:52
合計ジャッジ時間 13,064 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 534 ms
44,532 KB
testcase_01 AC 529 ms
44,784 KB
testcase_02 AC 527 ms
44,268 KB
testcase_03 AC 535 ms
44,144 KB
testcase_04 AC 546 ms
44,776 KB
testcase_05 AC 560 ms
44,528 KB
testcase_06 AC 553 ms
44,660 KB
testcase_07 AC 549 ms
44,656 KB
testcase_08 AC 552 ms
44,652 KB
testcase_09 AC 547 ms
45,172 KB
testcase_10 AC 542 ms
44,020 KB
testcase_11 AC 554 ms
44,400 KB
testcase_12 AC 553 ms
44,144 KB
testcase_13 AC 546 ms
44,524 KB
testcase_14 AC 566 ms
44,908 KB
testcase_15 AC 553 ms
44,140 KB
testcase_16 AC 570 ms
44,524 KB
testcase_17 AC 546 ms
44,532 KB
testcase_18 AC 564 ms
44,792 KB
testcase_19 AC 562 ms
44,016 KB
testcase_20 AC 550 ms
44,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・f = t^a + t^{-a} + t^b + t^{-b} + t^c + t^{-c}
・f^Tの係数 ([d,e])の和を求める問題
・ずらす。g = t^{20}f. 
・g^Tの係数([d+20T,e+20T])を求める問題
"""

import numpy as np

T,a,b,c,d,e = map(int,read().split())

MOD = 10 ** 9 + 7

f = np.zeros(42,np.int64)
for x in [-a,a,-b,b,-c,c]:
    f[20 + x] += 1

def fft_convolve(f, g, MOD = MOD):
    """
    数列 (多項式) f, g の畳み込みの計算.上下 15 bitずつ分けて計算することで,
    30 bit以下の整数,長さ 250000 程度の数列での計算が正確に行える.
    """
    fft = np.fft.rfft; ifft = np.fft.irfft
    Lf = len(f); Lg = len(g); L = Lf + Lg - 1
    fft_len = 1 << L.bit_length()
    fl = f & (1 << 15) - 1; fh = f >> 15
    gl = g & (1 << 15) - 1; gh = g >> 15
    conv = lambda f,g: ifft(fft(f,fft_len) * fft(g,fft_len))[:L]
    x = conv(fl, gl) % MOD
    y = conv(fl+fh, gl+gh) % MOD
    z = conv(fh, gh) % MOD
    a, b, c = map(lambda x: (x + .5).astype(np.int64), [x,y,z])
    return (a + ((b - a - c) << 15) + (c << 30)) % MOD

def power(f,n):
    if n == 1:
        return f.copy()
    g = power(f,n//2)
    g = fft_convolve(g,g)
    return fft_convolve(f,g) if n & 1 else g

F = power(f,T)

answer = F[d + 20 * T:e + 20 * T + 1].sum() % MOD
print(answer)
0