結果
問題 | No.1307 Rotate and Accumulate |
ユーザー |
|
提出日時 | 2020-12-04 21:08:08 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 911 ms / 5,000 ms |
コード長 | 1,456 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 83,928 KB |
最終ジャッジ日時 | 2024-09-15 07:52:10 |
合計ジャッジ時間 | 17,650 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
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 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)))