結果
| 問題 |
No.1307 Rotate and Accumulate
|
| コンテスト | |
| ユーザー |
sotanishy
|
| 提出日時 | 2020-12-05 20:53:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,257 ms / 5,000 ms |
| コード長 | 1,180 bytes |
| コンパイル時間 | 367 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 272,796 KB |
| 最終ジャッジ日時 | 2024-09-16 03:22:21 |
| 合計ジャッジ時間 | 14,607 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
import sys
input = sys.stdin.readline
class FFT:
@classmethod
def _dft(cls, f, inv):
from cmath import rect, pi
n = len(f)
if n == 1:
return
a = f[0::2]
b = f[1::2]
cls._dft(a, inv)
cls._dft(b, inv)
cur = 1
zeta = rect(1, inv * 2 * pi / n)
for i in range(n):
f[i] = a[i % (n // 2)] + cur * b[i % (n // 2)]
cur *= zeta
@classmethod
def convolve(cls, f, g):
n = 1
while n < len(f) + len(g):
n *= 2
nf = [0] * n
ng = [0] * n
for i in range(len(f)):
nf[i] = f[i]
ng[i] = g[i]
cls._dft(nf, 1)
cls._dft(ng, 1)
for i in range(n):
nf[i] *= ng[i]
cls._dft(nf, -1)
ret = [0] * n
for i in range(n):
ret[i] = nf[i].real / n
return ret
N, Q = map(int, input().split())
a = list(map(int, input().split()))
r = list(map(int, input().split()))
x = [0] * N
for i in r:
x[-i] += 1
ans = FFT.convolve(a, x)
ans = list(map(round, ans))
for i in range(N, len(ans)):
ans[i % N] += ans[i]
print(*ans[:N])
sotanishy