結果

問題 No.1307 Rotate and Accumulate
ユーザー wolgnikwolgnik
提出日時 2020-12-04 00:47:29
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 975 ms / 5,000 ms
コード長 452 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 72,284 KB
最終ジャッジ日時 2024-09-14 10:34:11
合計ジャッジ時間 19,638 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np
input = sys.stdin.readline
N, Q = map(int, input().split())
a = list(map(int, input().split()))
r = list(map(int, input().split()))
ln = 1 << 18
A = np.zeros(ln)
B = np.zeros(ln)
for i in range(N): A[N - i - 1] = a[i]
for q in r: B[q] += 1
C = np.fft.rfft(A) * np.fft.rfft(B)
c = np.fft.irfft(C)
res = [0] * N
for i in range(len(c)): res[i % N] += c[i]
res.reverse()
res = [int(res[i] + 0.5) for i in range(N)]
print(*res)
0