結果

問題 No.723 2つの数の和
ユーザー onakasuitacityonakasuitacity
提出日時 2020-10-17 15:14:15
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,164 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 293,244 KB
最終ジャッジ日時 2023-09-28 08:09:59
合計ジャッジ時間 35,742 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,177 ms
290,856 KB
testcase_01 AC 1,177 ms
291,696 KB
testcase_02 AC 1,187 ms
291,136 KB
testcase_03 AC 1,198 ms
288,096 KB
testcase_04 AC 1,196 ms
288,232 KB
testcase_05 AC 1,192 ms
288,308 KB
testcase_06 AC 1,223 ms
289,200 KB
testcase_07 AC 1,204 ms
292,112 KB
testcase_08 AC 1,201 ms
290,724 KB
testcase_09 AC 1,197 ms
288,084 KB
testcase_10 AC 1,203 ms
293,244 KB
testcase_11 AC 1,199 ms
289,808 KB
testcase_12 AC 1,190 ms
289,156 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 1,203 ms
290,128 KB
testcase_19 AC 1,209 ms
290,156 KB
testcase_20 AC 1,193 ms
290,848 KB
testcase_21 AC 1,215 ms
293,236 KB
testcase_22 AC 1,186 ms
290,860 KB
testcase_23 AC 1,192 ms
290,204 KB
testcase_24 AC 1,195 ms
290,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

from cmath import pi, rect
def _fft(A, inverse = False):
    N = len(A)
    logN = (N - 1).bit_length()
    step = N
    for k in range(logN):
        step >>= 1
        w = rect(1, pi / (1 << k) * (1 - 2 * inverse))
        wj = 1
        nA = [0] * N
        for j in range(1 << k):
            for i in range(1 << logN - k - 1):
                s, t = i + j * step, i + j * step + (N >> 1)
                ps, pt = i + j * step * 2, i + j * step * 2 + step
                nA[s], nA[t] = A[ps] + A[pt] * wj, A[ps] - A[pt] * wj
            wj *= w
        A = nA
    return A

def convolution(f, g):
    N = 1 << (len(f) + len(g) - 2).bit_length()
    Ff, Fg = _fft(f + [0] * (N - len(f))), _fft(g + [0] * (N - len(g)))
    fg = _fft([a * b / N for a, b in zip(Ff, Fg)], inverse = True)
    del fg[len(f) + len(g) - 1:]
    return fg

def resolve():
    n, x = map(int, input().split())
    f = [0] * 100001
    for a in map(int, input().split()):
        f[a] += 1
    f = convolution(f, f)
    print(round(f[x].real))
resolve()
0