Submission #11424821


Source Code Expand

class FFT():
    def __init__(self, n, p, w):
        # pは素数で, wは1のn乗根(mod p)
        # 例:(n,p,w)=(4,5,2),(8,17,2),(262144,1541406721,103)
        self.n = n
        self.p = p
        self.w = w
        self.rn = pow(n, p-2, p)
        self.rw = pow(w, p-2, p)

    def base(self, A, n, w):
        p = self.p
        for i in range(n-len(A)):
            A.append(0)
        if n == 1:
            return A
        F0 = self.base(A[0::2], n//2, pow(w, 2, p))
        F1 = self.base(A[1::2], n//2, pow(w, 2, p))
        x = 1
        F = []
        for i in range(n):
            f = (F0[i % (n//2)] + x * F1[i % (n//2)]) % p
            x = (x * w) % p
            F.append(f)
        return F

    def fft(self, A):
        return self.base(A, self.n, self.w)

    def ift(self, A):
        F = self.base(A, self.n, self.rw)
        return [(f * self.rn) % self.p for f in F]


if __name__ == '__main__':
    N = int(input())
    A, B = [0], [0]
    for i in range(1, N+1):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    n, p, w = 262144, 1541406721, 103
    fft = FFT(n, p, w)
    FA = fft.fft(A)
    FB = fft.fft(B)
    FC = [FA[i]*FB[i] for i in range(n)]
    C = fft.ift(FC)
    for k in range(1, 2*N+1):
        print(C[k])

Submission Info

Submission Time
Task C - 高速フーリエ変換
User fjhr
Language PyPy3 (2.4.0)
Score 100
Code Size 1337 Byte
Status AC
Exec Time 2331 ms
Memory 130472 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 1
AC × 33
Set Name Test Cases
Sample 00_sample_01
All 00_sample_01, 01_00_01, 01_01_19, 01_02_31, 01_03_22, 01_04_31, 01_05_40, 01_06_15, 01_07_39, 01_08_28, 01_09_30, 01_10_23, 01_11_33, 01_12_11, 01_13_28, 01_14_41, 01_15_26, 01_16_49, 01_17_34, 01_18_02, 01_19_33, 01_20_29, 02_00_51254, 02_01_82431, 02_02_17056, 02_03_34866, 02_04_6779, 02_05_65534, 02_06_65535, 02_07_65536, 02_08_65537, 02_09_65538, 02_10_100000
Case Name Status Exec Time Memory
00_sample_01 AC 1697 ms 123708 KB
01_00_01 AC 1707 ms 123708 KB
01_01_19 AC 1738 ms 122556 KB
01_02_31 AC 1746 ms 123068 KB
01_03_22 AC 1737 ms 121404 KB
01_04_31 AC 1713 ms 122044 KB
01_05_40 AC 1715 ms 122428 KB
01_06_15 AC 1719 ms 121916 KB
01_07_39 AC 1730 ms 122300 KB
01_08_28 AC 1735 ms 122428 KB
01_09_30 AC 1722 ms 122940 KB
01_10_23 AC 1719 ms 122172 KB
01_11_33 AC 1721 ms 121660 KB
01_12_11 AC 1711 ms 123068 KB
01_13_28 AC 1720 ms 122428 KB
01_14_41 AC 1737 ms 121788 KB
01_15_26 AC 1714 ms 123196 KB
01_16_49 AC 1729 ms 122172 KB
01_17_34 AC 1743 ms 122044 KB
01_18_02 AC 1698 ms 124220 KB
01_19_33 AC 1739 ms 122556 KB
01_20_29 AC 1736 ms 122300 KB
02_00_51254 AC 2141 ms 129448 KB
02_01_82431 AC 2260 ms 129448 KB
02_02_17056 AC 2008 ms 128296 KB
02_03_34866 AC 2099 ms 128168 KB
02_04_6779 AC 1963 ms 130472 KB
02_05_65534 AC 2191 ms 130088 KB
02_06_65535 AC 2208 ms 129064 KB
02_07_65536 AC 2212 ms 129576 KB
02_08_65537 AC 2231 ms 130216 KB
02_09_65538 AC 2222 ms 130088 KB
02_10_100000 AC 2331 ms 129064 KB