結果

問題 No.1307 Rotate and Accumulate
ユーザー sotanishysotanishy
提出日時 2020-12-05 20:53:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,374 ms / 5,000 ms
コード長 1,180 bytes
コンパイル時間 1,057 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 272,952 KB
最終ジャッジ日時 2023-10-14 08:14:57
合計ジャッジ時間 18,571 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,764 KB
testcase_01 AC 71 ms
71,568 KB
testcase_02 AC 70 ms
71,756 KB
testcase_03 AC 80 ms
76,516 KB
testcase_04 AC 83 ms
76,408 KB
testcase_05 AC 84 ms
76,204 KB
testcase_06 AC 82 ms
76,336 KB
testcase_07 AC 74 ms
71,808 KB
testcase_08 AC 1,367 ms
266,004 KB
testcase_09 AC 1,374 ms
267,276 KB
testcase_10 AC 736 ms
192,272 KB
testcase_11 AC 710 ms
186,536 KB
testcase_12 AC 716 ms
185,456 KB
testcase_13 AC 189 ms
89,476 KB
testcase_14 AC 397 ms
122,516 KB
testcase_15 AC 1,335 ms
265,828 KB
testcase_16 AC 1,372 ms
266,248 KB
testcase_17 AC 1,330 ms
265,908 KB
testcase_18 AC 1,313 ms
272,952 KB
testcase_19 AC 1,325 ms
272,784 KB
testcase_20 AC 1,312 ms
272,868 KB
testcase_21 AC 70 ms
71,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0