結果

問題 No.723 2つの数の和
ユーザー onakasuitacityonakasuitacity
提出日時 2020-10-17 15:15:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,033 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 292,552 KB
最終ジャッジ日時 2023-09-28 08:10:32
合計ジャッジ時間 27,422 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,016 ms
291,668 KB
testcase_01 AC 1,010 ms
291,164 KB
testcase_02 AC 970 ms
290,992 KB
testcase_03 AC 975 ms
288,752 KB
testcase_04 AC 950 ms
288,292 KB
testcase_05 AC 958 ms
288,636 KB
testcase_06 AC 976 ms
288,520 KB
testcase_07 AC 969 ms
292,360 KB
testcase_08 AC 986 ms
290,912 KB
testcase_09 AC 1,015 ms
287,900 KB
testcase_10 AC 976 ms
291,064 KB
testcase_11 AC 956 ms
292,064 KB
testcase_12 AC 1,023 ms
289,528 KB
testcase_13 AC 1,016 ms
288,440 KB
testcase_14 AC 1,029 ms
292,236 KB
testcase_15 AC 981 ms
292,552 KB
testcase_16 AC 1,033 ms
289,668 KB
testcase_17 AC 954 ms
288,928 KB
testcase_18 AC 960 ms
290,968 KB
testcase_19 AC 976 ms
290,176 KB
testcase_20 AC 959 ms
291,564 KB
testcase_21 AC 960 ms
291,592 KB
testcase_22 AC 978 ms
291,700 KB
testcase_23 AC 966 ms
290,460 KB
testcase_24 AC 962 ms
291,248 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)
    if x >= len(f):
        print(0)
    else:
        print(round(f[x].real))
resolve()
0