結果

問題 No.1307 Rotate and Accumulate
ユーザー shotoyooshotoyoo
提出日時 2020-12-04 21:07:28
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
RE  
実行時間 -
コード長 1,520 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 29,896 KB
最終ジャッジ日時 2023-10-13 10:48:34
合計ジャッジ時間 5,591 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

import numpy as np
# FFT
import numpy as np
M = 998244353
a = np.array(a, dtype=np.int64)
b = np.array(b, dtype=np.int64)
def fft(a,b):
    l = 1
    while 2 * l < len(a) + len(b) - 1:
        l *= 2
    l *= 2
    c = np.fft.irfft((np.fft.rfft(a,l))*(np.fft.rfft(b,l)),l)
    c = np.rint(c).astype(np.int64)
    return c
def fft_large(a,b):
    d = 30000
    a1, a2 = np.divmod(a,d)
    b1, b2 = np.divmod(b,d)
    aa = fft(a1,b1) % M
    bb = fft(a2,b2) % M
    cc = (fft(a1+a2, b1+b2) - (aa+bb)) % M
    h = (((aa*d)%M)*d  + cc*d + bb) % M
    return h
def fft_large(a,b):
    """精度が足りないときはこちら
    """
    d = 1<<10
    a1, a2 = np.divmod(a,d*d)
    a2, a3 = np.divmod(a2,d)
    b1, b2 = np.divmod(b,d*d)
    b2, b3 = np.divmod(b2,d)
    aa = fft(a1,b1) % M
    bb = fft(a2,b2) % M
    cc = fft(a3,b3) % M
    dd = (fft(a1+a2, b1+b2) - (aa+bb)) % M
    ee = (fft(a2+a3, b2+b3) - (bb+cc)) % M
    ff = (fft(a1+a3, b1+b3) - (aa+cc)) % M
    h = (((aa*d*d)%M)*d*d + ((dd*d*d)%M)*d + (bb+ff)*d*d + ee*d + cc) % M
    return h

n,q = list(map(int, input().split()))
a = np.array(list(map(int, input().split())), dtype=np.int64)
# r = np.array(list(map(int, input().split())), dtype=np.int64)
r = list(map(int, input().split()))
c = [0]*n
for num in r:
    c[(-num)%n] += 1
v = fft_large(a,c)
vv = (v[:n] + v[n:2*n]).tolist()
write(" ".join(map(str, vv)))
0